Warning: session_start(): open(/var/lib/php/sessions/sess_msv14a6vdj2f1g9p164r2mk4nq, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!752
p {
test("{[(a)]}", true); // ok
test("[(a)"); // not closed
test("a)"); // not opened
test("(a)}"); // not opened
test("(a]"); // mismatch
print("\nALL TESTS OK");
}
static void test(S s) {
test(s, false);
}
static void test(S s, bool ok) {
assertEquals(s, ok, testImpl(s));
print("ok");
}
static bool testImpl(S s) {
print();
print(s);
// not <> as they are ambiguous (< is also a comparison operator)
S op = "([{", close = ")]}";
L tok = javaTok(s);
new Map map;
L stack = getBracketMap2(tok, map, op, close);
if (nempty(stack)) {
print("Bad hygiene - " + n(l(stack), "bracket") + " not closed");
false;
}
if (map.containsKey(0)) {
print("Bad hygiene - bracket not opened (" + quote(tok.get(map.get(0))) + ")");
false;
}
for (int i : keys(map)) {
int j = map.get(i);
S a = tok.get(i), b = tok.get(j);
//print("i=" + i + ", j= " + j + ", a=" + quote(a) + ", b=" + quote(b));
int ai = op.indexOf(a), bi = close.indexOf(b);
if (ai != bi) {
print("Bad hygiene - brackets don't match (" + quote(a) + " vs " + quote(b) + ")");
false;
}
}
print("Hygiene OK!");
true;
}