Skip to content

Commit 2c0c669

Browse files
committed
Update isupper
1 parent 29ef81e commit 2c0c669

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

larkjs/lark.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ function list_repeat(list, count) {
306306
}
307307

308308
function isupper(a) {
309-
return /^[A-Z_$]*$/.test(a);
309+
return /^[^a-z]*[A-Z][^a-z]*$/.test(a);
310310
}
311311

312312
function rsplit(s, delimiter, limit) {
@@ -3981,4 +3981,5 @@ module.exports = {
39813981
Indenter,
39823982
PythonIndenter,
39833983
get_parser,
3984+
isupper,
39843985
};

test/test.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
const {TestTrees} = require("./test_trees.js");
2+
const {TestUtils} = require("./test_utils.js");
23

34
function run_test_class(cls) {
4-
describe(cls.constructor.name, function() {
5+
describe(cls.constructor.name, function() {
56

6-
let test = new cls();
7-
test.setUp();
8-
let test_names = Object.getOwnPropertyNames(cls.prototype).filter((prop) => prop.startsWith("test_"))
9-
for (const name of test_names) {
10-
it(name, () => {test[name]()})
11-
}
12-
});
7+
let test = new cls();
8+
if (test.setUp) {
9+
test.setUp();
10+
}
11+
let test_names = Object.getOwnPropertyNames(cls.prototype).filter((prop) => prop.startsWith("test_"))
12+
for (const name of test_names) {
13+
it(name, () => {test[name]()})
14+
}
15+
});
1316
}
1417

15-
run_test_class(TestTrees);
18+
run_test_class(TestTrees);
19+
run_test_class(TestUtils);

test/test_utils.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const _ = require("lodash");
2+
const lark = require("../larkjs/lark.js");
3+
const assert = require('assert');
4+
5+
const {
6+
isupper,
7+
} = lark;
8+
9+
class TestCase {
10+
assertEqual(a, b) {
11+
assert(_.isEqual(a, b), "Not equal:", a, b);
12+
}
13+
}
14+
15+
class TestUtils extends TestCase {
16+
test_is_upper_ignore_0() {
17+
this.assertEqual(isupper('__IGNORE_0'), true);
18+
}
19+
20+
test_is_upper_hello() {
21+
this.assertEqual(isupper('HELLO'), true);
22+
}
23+
24+
test_is_upper_foo_bar() {
25+
this.assertEqual(isupper('FOO_BAR'), true);
26+
}
27+
28+
test_is_upper_foo_bar_baz() {
29+
this.assertEqual(isupper('FOO-BAR BAZ'), true);
30+
}
31+
32+
test_is_upper_hello_lowercase() {
33+
this.assertEqual(isupper('Hello'), false);
34+
}
35+
36+
test_is_upper_hell_o_uppercase() {
37+
this.assertEqual(isupper('HellO'), false);
38+
}
39+
40+
test_is_upper_single_digit() {
41+
this.assertEqual(isupper('0'), false);
42+
}
43+
44+
test_is_upper_numbers() {
45+
this.assertEqual(isupper('123'), false);
46+
}
47+
}
48+
49+
module.exports = { TestUtils };

0 commit comments

Comments
 (0)