-
Notifications
You must be signed in to change notification settings - Fork 13
Add test for Number.prototype.chr
goody
#395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
miorel
merged 9 commits into
code-chronicles-code:main
from
Gobleizer:test/number-prototype-chr
Sep 21, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb70e28
test: initial test set up
Gobleizer 2ad7586
test: provides tests for typescript Number chr method
Gobleizer a453ab1
fix: replaces incompatible characters
Gobleizer 86a35f3
fix: removes repetitive tests
Gobleizer 354da9b
fix: refactor tests for readability
Gobleizer 3ffe581
fix: break up tests for readability
Gobleizer 0a6de0c
Merge branch 'main' into test/number-prototype-chr
Gobleizer b51df98
Merge branch 'main' into test/number-prototype-chr
Gobleizer cbe71fb
fix: removes unnecessary test
Gobleizer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
workspaces/adventure-pack/goodies/typescript/Number.prototype.chr/index.test.ts
This file contains hidden or 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,72 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { describe, expect, it } from "@jest/globals"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import "./index"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
describe("Number.prototype.chr", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
describe("converts ASCII codepoint to ASCII string", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it.each([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 65, expected: "A" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 10, expected: "\n" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 61, expected: "=" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 126, expected: "~" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 32, expected: " " }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 48, expected: "0" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
])( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"converts ASCII codepoint $codepoint to ASCII string $expected", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
({ codepoint, expected }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expect(codepoint.chr()).toBe(expected); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
describe("converts codepoint to emoji", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it.each([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 129302, expected: "🤖" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 129412, expected: "🦄" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
])( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"converts codepoint $codepoint to emoji $expected", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
({ codepoint, expected }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expect(codepoint.chr()).toBe(expected); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
describe("converts hex codepoint to string", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it.each([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 0x404, expected: "Є" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 0x24, expected: "$" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 0x1f303, expected: "🌃" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ codepoint: 0x1f92a, expected: "🤪" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
])( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"converts hex codepoint $codepoint to string $expected", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
({ codepoint, expected }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expect(codepoint.chr()).toBe(expected); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
describe("handles edgecases appropiately by returning null char or throwing error.", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it("converts zero to null character", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expect((0).chr()).toBe("\0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it.each([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ edgecase: -1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ edgecase: 11120651 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ edgecase: Infinity }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ edgecase: -Infinity }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ edgecase: 1.5 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ edgecase: 1e-2 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ edgecase: 0xffffff }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
])( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"handles number $edgecase outside unicode range by throwing range error", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
({ edgecase }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expect(() => edgecase.chr()).toThrow(RangeError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it("handles incompatible types that resolve to NaN by throwing range error", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expect(() => NaN.chr()).toThrow(RangeError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+53
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hex only exists for the developer's benefit:
So I'm not sure we gain from having a hex-specific section, it's just another way of writing valid integers.
Imo we can move the
0x24
into the ASCII codepoints test cases (and we'll just have one of the ASCII codepoints written as hex, while others aren't). Likewise we can move the emoji ones into the emoji test, and have some of those codepoints written as hex and some as decimal.The Є test can either be removed entirely or have its own test (non-ASCII non-emoji?).