@@ -83,4 +83,56 @@ describe("Test checkString", () => {
8383 expect ( check ( "female" , s ) ) . toEqual ( true ) ;
8484 } ) ;
8585
86+ it ( "check numeric string" , ( ) => {
87+ const s = { type : "string" , numeric : true } ;
88+
89+ expect ( check ( "123.1s0" , s ) ) . toEqual ( { type : "stringNumeric" , expected : "A numeric string" , actual : "123.1s0" } ) ;
90+ expect ( check ( "x" , s ) ) . toEqual ( { type : "stringNumeric" , expected : "A numeric string" , actual : "x" } ) ;
91+ expect ( check ( "" , s ) ) . toEqual ( { type : "stringNumeric" , expected : "A numeric string" , actual : "" } ) ;
92+ expect ( check ( " " , s ) ) . toEqual ( { type : "stringNumeric" , expected : "A numeric string" , actual : " " } ) ;
93+
94+ expect ( check ( "123" , s ) ) . toEqual ( true ) ;
95+ expect ( check ( "-123" , s ) ) . toEqual ( true ) ;
96+ expect ( check ( "123.10" , s ) ) . toEqual ( true ) ;
97+ expect ( check ( "-123.10" , s ) ) . toEqual ( true ) ;
98+ } ) ;
99+
100+ it ( "check alphabetic string" , ( ) => {
101+ const s = { type : "string" , alpha : true } ;
102+
103+ expect ( check ( "3312" , s ) ) . toEqual ( { type : "stringAlpha" , expected : "An alphabetic string" , actual : "3312" } ) ;
104+ expect ( check ( "h3ll0" , s ) ) . toEqual ( { type : "stringAlpha" , expected : "An alphabetic string" , actual : "h3ll0" } ) ;
105+ expect ( check ( "us3rnam3" , s ) ) . toEqual ( { type : "stringAlpha" , expected : "An alphabetic string" , actual : "us3rnam3" } ) ;
106+
107+ expect ( check ( "username" , s ) ) . toEqual ( true ) ;
108+ expect ( check ( "hello" , s ) ) . toEqual ( true ) ;
109+ expect ( check ( "elliot" , s ) ) . toEqual ( true ) ;
110+
111+ } ) ;
112+
113+ it ( "check alphanumeric string" , ( ) => {
114+ const s = { type : "string" , alphanum : true } ;
115+
116+ expect ( check ( "hello_world" , s ) ) . toEqual ( { type : "stringAlphanum" , expected : "An alphanumeric string" , actual : "hello_world" } ) ;
117+ expect ( check ( "print()" , s ) ) . toEqual ( { type : "stringAlphanum" , expected : "An alphanumeric string" , actual : "print()" } ) ;
118+ expect ( check ( "user.name" , s ) ) . toEqual ( { type : "stringAlphanum" , expected : "An alphanumeric string" , actual : "user.name" } ) ;
119+
120+ expect ( check ( "p4ssword" , s ) ) . toEqual ( true ) ;
121+ expect ( check ( "anarchy77" , s ) ) . toEqual ( true ) ;
122+ } ) ;
123+
124+ it ( "check alphadash string" , ( ) => {
125+ const s = { type : "string" , alphadash : true } ;
126+
127+ expect ( check ( "hello world" , s ) ) . toEqual ( { type : "stringAlphadash" , expected : "An alphadash string" , actual : "hello world" } ) ;
128+ expect ( check ( "hello.world" , s ) ) . toEqual ( { type : "stringAlphadash" , expected : "An alphadash string" , actual : "hello.world" } ) ;
129+ expect ( check ( "spaced string" , s ) ) . toEqual ( { type : "stringAlphadash" , expected : "An alphadash string" , actual : "spaced string" } ) ;
130+
131+
132+ expect ( check ( "hello_world" , s ) ) . toEqual ( true ) ;
133+ expect ( check ( "dashed_string" , s ) ) . toEqual ( true ) ;
134+
135+ } ) ;
136+
137+
86138} ) ;
0 commit comments