Last active
November 9, 2018 13:48
-
-
Save kaseopea/6e251f06439a936c5aa2774e12686876 to your computer and use it in GitHub Desktop.
ES6 Katas template strings - String.raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 4: template strings - String.raw | |
// To do: make all tests pass, leave the asserts unchanged! | |
// Follow the hints of the failure messages! | |
describe('Use the `raw` property of tagged template strings 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[0][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` | |
`, 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); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment