11import { attest , contextualize } from "@ark/attest"
2- import { nearestFloat } from "@ark/util"
2+ import { isNumericString , isWellFormedNumber , nearestFloat } from "@ark/util"
33
44contextualize ( ( ) => {
55 describe ( "nearestFloat" , ( ) => {
@@ -25,4 +25,45 @@ contextualize(() => {
2525 attest ( nearestFloat ( - 5555555555555555 , "-" ) ) . equals ( - 5555555555555556 )
2626 } )
2727 } )
28+
29+ describe ( "number matchers" , ( ) => {
30+ it ( "wellFormedNumberMatcher rejects decimal-only numbers" , ( ) => {
31+ attest ( isWellFormedNumber ( ".5" ) ) . equals ( false )
32+ attest ( isWellFormedNumber ( "0.5" ) ) . equals ( true )
33+ } )
34+
35+ it ( "numericStringMatcher accepts decimal-only numbers" , ( ) => {
36+ attest ( isNumericString ( ".5" ) ) . equals ( true )
37+ attest ( isNumericString ( "0.5" ) ) . equals ( true )
38+ } )
39+
40+ it ( "wellFormedNumberMatcher rejects trailing zeros in decimals" , ( ) => {
41+ attest ( isWellFormedNumber ( "0.10" ) ) . equals ( false )
42+ attest ( isWellFormedNumber ( "0.1" ) ) . equals ( true )
43+ } )
44+
45+ it ( "numericStringMatcher accepts trailing zeros in decimals" , ( ) => {
46+ attest ( isNumericString ( "0.10" ) ) . equals ( true )
47+ attest ( isNumericString ( "0.1" ) ) . equals ( true )
48+ } )
49+
50+ it ( "both matchers reject negative zero" , ( ) => {
51+ attest ( isWellFormedNumber ( "-0" ) ) . equals ( false )
52+ attest ( isNumericString ( "-0" ) ) . equals ( false )
53+ } )
54+
55+ it ( "both matchers accept valid integers" , ( ) => {
56+ attest ( isWellFormedNumber ( "123" ) ) . equals ( true )
57+ attest ( isNumericString ( "123" ) ) . equals ( true )
58+ attest ( isWellFormedNumber ( "-123" ) ) . equals ( true )
59+ attest ( isNumericString ( "-123" ) ) . equals ( true )
60+ } )
61+
62+ it ( "both matchers accept valid decimals" , ( ) => {
63+ attest ( isWellFormedNumber ( "123.456" ) ) . equals ( true )
64+ attest ( isNumericString ( "123.456" ) ) . equals ( true )
65+ attest ( isWellFormedNumber ( "-123.456" ) ) . equals ( true )
66+ attest ( isNumericString ( "-123.456" ) ) . equals ( true )
67+ } )
68+ } )
2869} )
0 commit comments