This repository has been archived by the owner on Sep 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
88 lines (86 loc) · 3.15 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var assert = require("assert");
const areParenthesesNestedProperly = require("./lisp-parentheses-checker");
describe("Input with parentheses that match", () => {
it("should return true because the parentheses match", () => {
assert.equal(areParenthesesNestedProperly("((2 * 2) (3 * 5))"), true);
});
});
describe("Input with parentheses that do not match", () => {
it("should return false because the parentheses don't match", () => {
assert.equal(areParenthesesNestedProperly("((2 * 2) (3 * 5)"), false);
});
});
describe("Code with open parentheses in a comment", () => {
const testInput = `((1 + 1) ; (code with a parenthesis in a comment (
)`;
it("should return true when a parentheses are in a comment line but the rest of the input is valid", () => {
assert.equal(areParenthesesNestedProperly(testInput), true);
});
});
describe("Code with open parentheses and a semicolon in quotes", () => {
const testInput = `((1 + 1) "; (code with a parenthesis in a comment (")`;
it("should return true when a parentheses are quotes and the rest of the input is valid", () => {
assert.equal(areParenthesesNestedProperly(testInput), true);
});
});
describe("Code with valid code following an empty line after a comment should be valid", () => {
const testInput = `(
(5 * 2) ;; This is a comment
(10 * 5)
)`;
it("should return true when a parenthesis is in a comment line", () => {
assert.equal(areParenthesesNestedProperly(testInput), true);
});
});
describe("Code with open parentheses in a comment", () => {
it("should return false when an open parenthesis is outside of a comment and a closed parenthesis is inside", () => {
assert.equal(
areParenthesesNestedProperly(
"( ; (code with open parentheses in a comment ()"
),
false
);
});
});
describe("Code with open parentheses in quotes", () => {
it("should return true when a parenthesis is in quotes but there are surrounding matching parentheses", () => {
assert.equal(
areParenthesesNestedProperly(
'("(code with open parentheses in quotes (")'
),
true
);
});
});
describe("Code with semicolons in quotes", () => {
it("should return true when a parenthesis is in quotes but there are surrounding matching parentheses", () => {
assert.equal(
areParenthesesNestedProperly(
'("(code ; with open parentheses in quotes (")'
),
true
);
});
});
describe("Multiline double quotes containing parentheses should not make open parentheses valid again", () => {
const testInput = `((11 * 11)
"
(101 * 210
"
(101 * 210)
)`;
it("should return true when a quote spans multiple lines and an open parentheses is in the quotes", () => {
assert.equal(areParenthesesNestedProperly(testInput), true);
});
});
describe("Multiline double quotes containing parentheses should not make open parentheses valid again", () => {
const testInput = `((11 * 11)
"
(101 * 210
"
(101 * 210)
)))))`;
it("should return false when there are too many closing parentheses", () => {
assert.equal(areParenthesesNestedProperly(testInput), false);
});
});