-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from nainemom/substr
Substr
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import assert from "assert"; | ||
import { substr } from "../src/index"; | ||
|
||
describe("Substr", () => { | ||
const string = "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe."; | ||
const unicodeString = "دانشگاهی که دانشگاه نباشد، دانشگاه نیست."; | ||
const emojiString = "Emojis 👍🏽 are 🍆 poison. 🌮s are bad."; | ||
|
||
it("Substrs latin text correctly", () => { | ||
assert.strictEqual(substr("Iñtërnâtiônàlizætiøn☃", 0, 10), "Iñtërnâtiô"); | ||
assert.strictEqual(substr(string, 25, 32), string.substr(25, 32)); | ||
}); | ||
|
||
it("Substrs unicode text correctly", () => { | ||
assert.strictEqual(substr(unicodeString, 0, 11), "دانشگاهی که"); | ||
assert.strictEqual(substr(emojiString, 7, 7), "👍🏽 are 🍆"); | ||
}); | ||
|
||
it("Substrs if arguments are unspecified", () => { | ||
assert.strictEqual(substr(string, 10), string.substr(10)); | ||
assert.strictEqual(substr(string, 120), string.substr(120)); | ||
assert.strictEqual(substr(string, '1', '2'), string.substr('1', '2')); | ||
assert.strictEqual(substr(string), string); | ||
}); | ||
|
||
it("Substrs even with negative arguments", () => { | ||
assert.strictEqual(substr(string, -4), string.substr(-4)); | ||
assert.strictEqual(substr(string, -4, -1), string.substr(-4, -1)); | ||
}); | ||
|
||
it("Throws an error if wrong arguments are specified.", () => { | ||
assert.throws(() => substr(12, 1, 2), Error); | ||
}); | ||
}); |