Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update isupper #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion larkjs/lark.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function list_repeat(list, count) {
}

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

function rsplit(s, delimiter, limit) {
Expand Down Expand Up @@ -3981,4 +3981,5 @@ module.exports = {
Indenter,
PythonIndenter,
get_parser,
isupper,
};
22 changes: 13 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const {TestTrees} = require("./test_trees.js");
const {TestUtils} = require("./test_utils.js");

function run_test_class(cls) {
describe(cls.constructor.name, function() {
describe(cls.constructor.name, function() {

let test = new cls();
test.setUp();
let test_names = Object.getOwnPropertyNames(cls.prototype).filter((prop) => prop.startsWith("test_"))
for (const name of test_names) {
it(name, () => {test[name]()})
}
});
let test = new cls();
if (test.setUp) {
test.setUp();
}
let test_names = Object.getOwnPropertyNames(cls.prototype).filter((prop) => prop.startsWith("test_"))
for (const name of test_names) {
it(name, () => {test[name]()})
}
});
}

run_test_class(TestTrees);
run_test_class(TestTrees);
run_test_class(TestUtils);
49 changes: 49 additions & 0 deletions test/test_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const _ = require("lodash");
const lark = require("../larkjs/lark.js");
const assert = require('assert');

const {
isupper,
} = lark;

class TestCase {
assertEqual(a, b) {
assert(_.isEqual(a, b), "Not equal:", a, b);
}
}

class TestUtils extends TestCase {
test_is_upper_ignore_0() {
this.assertEqual(isupper('__IGNORE_0'), true);
}

test_is_upper_hello() {
this.assertEqual(isupper('HELLO'), true);
}

test_is_upper_foo_bar() {
this.assertEqual(isupper('FOO_BAR'), true);
}

test_is_upper_foo_bar_baz() {
this.assertEqual(isupper('FOO-BAR BAZ'), true);
}

test_is_upper_hello_lowercase() {
this.assertEqual(isupper('Hello'), false);
}

test_is_upper_hell_o_uppercase() {
this.assertEqual(isupper('HellO'), false);
}

test_is_upper_single_digit() {
this.assertEqual(isupper('0'), false);
}

test_is_upper_numbers() {
this.assertEqual(isupper('123'), false);
}
}

module.exports = { TestUtils };