Skip to content

Instantly share code, notes, and snippets.

@reneviering
Last active October 5, 2017 18:40
Show Gist options
  • Save reneviering/d79de8b7154d8015341d8895eb311861 to your computer and use it in GitHub Desktop.
Save reneviering/d79de8b7154d8015341d8895eb311861 to your computer and use it in GitHub Desktop.
// 4: template strings - String.raw
// To do: make all tests pass, leave the asserts unchanged!
describe('on tagged template strings you can use the `raw` property like so `s.raw`', function() {
it('the `raw` property accesses the string as it was entered', function() {
function firstChar(strings) {
return strings.raw;
}
assert.equal(firstChar`\n`, '\\n');
});
it('`raw` can access the backslash of a line-break', function() {
function firstCharEntered(strings) {
var lineBreak = strings.raw.toString()[0];
return lineBreak;
}
assert.equal(firstCharEntered`\n`, '\\');
});
describe('`String.raw` as a static function', function(){
it('concats the raw strings', function() {
var expected = '\\n';
assert.equal(String.raw`\n`, expected);
});
it('two raw-templates-string-backslashes equal two escaped backslashes', function() {
const TWO_BACKSLASHES = '\\\\';
assert.equal(String.raw`\\`, TWO_BACKSLASHES);
});
it('works on unicodes too', function() {
var smilie = '\\u{1F600}';
var actual = String.raw`\u{1F600}`;
assert.equal(actual, smilie);
});
});
});
@reneviering
Copy link
Author

reneviering commented Jun 11, 2016

Challenge 4/79 (template strings - String.raw)

First i struggled a little with »backslashes vs. escaped backslashes«. But after i realized that »two raw-templates-string-backslashes equal two escaped backslashes« as i could read in the following tests, it was pretty easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment