Skip to content

Commit dcb3b7e

Browse files
add charset tests
1 parent 5387922 commit dcb3b7e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/rules/string.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,42 @@ describe("Test checkString", () => {
9090
expect(check("-123.10", s)).toEqual(true);
9191
});
9292

93+
it("check alphabetic string", () => {
94+
const s = {type: "string", alpha: true};
95+
96+
expect(check("3312", s)).toEqual({type: "stringAlpha", expected: "An alphabetic string", actual: "3312"});
97+
expect(check("h3ll0", s)).toEqual({type: "stringAlpha", expected: "An alphabetic string", actual: "h3ll0"});
98+
expect(check("us3rnam3", s)).toEqual({type: "stringAlpha", expected: "An alphabetic string", actual: "us3rnam3"});
99+
100+
expect(check("username", s)).toEqual(true);
101+
expect(check("hello", s)).toEqual(true);
102+
expect(check("elliot", s)).toEqual(true);
103+
104+
});
105+
106+
it("check alphanumeric string", () => {
107+
const s = {type: "string", alphanum: true};
108+
109+
expect(check("hello_world", s)).toEqual({type: "stringAlphanum", expected: "An alphanumeric string", actual: "hello_world"});
110+
expect(check("print()", s)).toEqual({type: "stringAlphanum", expected: "An alphanumeric string", actual: "print()"});
111+
expect(check("user.name", s)).toEqual({type: "stringAlphanum", expected: "An alphanumeric string", actual: "user.name"});
112+
113+
expect(check("p4ssword", s)).toEqual(true);
114+
expect(check("anarchy77", s)).toEqual(true);
115+
});
116+
117+
it("check alphadash string", () => {
118+
const s = {type: "string", alphadash: true};
119+
120+
expect(check("hello world", s)).toEqual({type: "stringAlphadash", expected: "An alphadash string", actual: "hello world"});
121+
expect(check("hello.world", s)).toEqual({type: "stringAlphadash", expected: "An alphadash string", actual: "hello.world"});
122+
expect(check("spaced string", s)).toEqual({type: "stringAlphadash", expected: "An alphadash string", actual: "spaced string"});
123+
124+
125+
expect(check("hello_world", s)).toEqual(true);
126+
expect(check("dashed_string", s)).toEqual(true);
127+
128+
});
129+
130+
93131
});

0 commit comments

Comments
 (0)