From e3388d5fc71b46f70fc853e9c8c8777c1691b7f9 Mon Sep 17 00:00:00 2001 From: Justin Meza Date: Sun, 19 Jul 2015 11:22:56 -0700 Subject: [PATCH] fixed string interpolation during comparison (as pointed out by @Lucki, thanks) --- interpreter.c | 12 +++++- .../5-String/3-Comparison/CMakeLists.txt | 2 + .../3-Types/5-String/3-Comparison/test.lol | 41 +++++++++++++++++++ .../3-Types/5-String/3-Comparison/test.out | 8 ++++ .../3-Types/5-String/3-Comparison/test.readme | 2 + .../1.3-Tests/3-Types/5-String/CMakeLists.txt | 1 + unicode.c | 2 +- 7 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 test/1.3-Tests/3-Types/5-String/3-Comparison/CMakeLists.txt create mode 100644 test/1.3-Tests/3-Types/5-String/3-Comparison/test.lol create mode 100644 test/1.3-Tests/3-Types/5-String/3-Comparison/test.out create mode 100644 test/1.3-Tests/3-Types/5-String/3-Comparison/test.readme diff --git a/interpreter.c b/interpreter.c index 3ced195..4803263 100644 --- a/interpreter.c +++ b/interpreter.c @@ -2990,8 +2990,18 @@ ValueObject *interpretEqualityOpExprNode(OpExprNode *expr, return NULL; } } - else + else { + /* If comparing strings, interpolate them first */ + ValueObject *old1 = val1; + ValueObject *old2 = val2; + if (val1->type == VT_STRING) { + val1 = castStringExplicit(val1, scope); + val2 = castStringExplicit(val2, scope); + deleteValueObject(old1); + deleteValueObject(old2); + } ret = BoolOpJumpTable[expr->type - OP_EQ][val1->type][val2->type](val1, val2); + } deleteValueObject(val1); deleteValueObject(val2); return ret; diff --git a/test/1.3-Tests/3-Types/5-String/3-Comparison/CMakeLists.txt b/test/1.3-Tests/3-Types/5-String/3-Comparison/CMakeLists.txt new file mode 100644 index 0000000..b14fec8 --- /dev/null +++ b/test/1.3-Tests/3-Types/5-String/3-Comparison/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(AddLolTest) +ADD_LOL_TEST(3-Comparison OUTPUT test.out) diff --git a/test/1.3-Tests/3-Types/5-String/3-Comparison/test.lol b/test/1.3-Tests/3-Types/5-String/3-Comparison/test.lol new file mode 100644 index 0000000..ac3d3df --- /dev/null +++ b/test/1.3-Tests/3-Types/5-String/3-Comparison/test.lol @@ -0,0 +1,41 @@ +HAI 1.3 + CAN HAS STRING? + + I HAS A string ITZ "::hello" + + I HAS A char ITZ I IZ STRING'Z AT YR string AN YR 0 MKAY + VISIBLE char AN " - " AN "::" + + BOTH SAEM char AN "::", O RLY? + YA RLY + VISIBLE "success" + NO WAI + VISIBLE "fail" + OIC + + VISIBLE char AN " - " AN ":(3A)" + BOTH SAEM char AN ":(3A)", O RLY? + YA RLY + VISIBLE "success" + NO WAI + VISIBLE "fail" + OIC + + I HAS A char2 ITZ I IZ STRING'Z AT YR string AN YR 1 MKAY + VISIBLE char2 AN " - " AN "h" + BOTH SAEM char2 AN "h", O RLY? + YA RLY + VISIBLE "success" + NO WAI + VISIBLE "fail" + OIC + + I HAS A char3 ITZ "::" + VISIBLE char3 AN " - " AN "::" + BOTH SAEM char3 AN "::", O RLY? + YA RLY + VISIBLE "success" + NO WAI + VISIBLE "fail" + OIC +KTHXBYE diff --git a/test/1.3-Tests/3-Types/5-String/3-Comparison/test.out b/test/1.3-Tests/3-Types/5-String/3-Comparison/test.out new file mode 100644 index 0000000..87bc655 --- /dev/null +++ b/test/1.3-Tests/3-Types/5-String/3-Comparison/test.out @@ -0,0 +1,8 @@ +: - : +success +: - : +success +h - h +success +: - : +success diff --git a/test/1.3-Tests/3-Types/5-String/3-Comparison/test.readme b/test/1.3-Tests/3-Types/5-String/3-Comparison/test.readme new file mode 100644 index 0000000..192d16b --- /dev/null +++ b/test/1.3-Tests/3-Types/5-String/3-Comparison/test.readme @@ -0,0 +1,2 @@ +This test checks that strings containing escape sequences are compared +correctly. diff --git a/test/1.3-Tests/3-Types/5-String/CMakeLists.txt b/test/1.3-Tests/3-Types/5-String/CMakeLists.txt index d588abd..6dccc23 100644 --- a/test/1.3-Tests/3-Types/5-String/CMakeLists.txt +++ b/test/1.3-Tests/3-Types/5-String/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(1-Escapes) add_subdirectory(2-Syntax) +add_subdirectory(3-Comparison) diff --git a/unicode.c b/unicode.c index 4765591..5606011 100644 --- a/unicode.c +++ b/unicode.c @@ -43575,7 +43575,7 @@ long convertNormativeNameToCodePoint(const char *name) { int index = binarySearch(names, 0, NUM_UNICODE - 1, name); if (index < 0) { - fprintf(stderr, "Invalid Unicode normative name.\n"); + fprintf(stderr, "Invalid Unicode normative name: %s.\n", name); return -1; } else