Skip to content

Commit

Permalink
Reinstated some of the e2e tests that work...
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyarnold committed Mar 15, 2017
1 parent bc50fcd commit 67aa95e
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 264 deletions.
36 changes: 18 additions & 18 deletions spec/e2e/block.spec.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#include "spec/spec.h"

TEST_CASE("Block set/get") {
REQUIRE(resultOf("x = {}; x") == "{}");
REQUIRE(resultOf("x = { a = 1 }; x.a") == "1");
}
// TEST_CASE("Block set/get") {
// REQUIRE(resultOf("x = {}; x") == "{}");
// REQUIRE(resultOf("x = { a = 1 }; x.a") == "1");
// }

TEST_CASE("Assignment outside of block") {
REQUIRE(resultOf("x = {}; x.y = 1; x.y") == "1");
}
// TEST_CASE("Assignment outside of block") {
// REQUIRE(resultOf("x = {}; x.y = 1; x.y") == "1");
// }

TEST_CASE("Nested blocks") {
REQUIRE(resultOf(R"(
Utils = {
Math = {
pi = 3
area = fn (diameter) { pi * diameter }
}
}
// TEST_CASE("Nested blocks") {
// REQUIRE(resultOf(R"(
// Utils = {
// Math = {
// pi = 3
// area = fn (diameter) { pi * diameter }
// }
// }

Utils.Math.area(3)
)") == "9");
}
// Utils.Math.area(3)
// )") == "9");
// }

// TODO: .keys
//
Expand Down
52 changes: 26 additions & 26 deletions spec/e2e/bool.spec.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#include "spec/spec.h"

TEST_CASE("Boolean set/get") {
REQUIRE(resultOf("x = true; x") == "true");
REQUIRE(resultOf("x = true; x").asBool() == true);
}

TEST_CASE("and") {
REQUIRE(resultOf("true and true") == "true");
REQUIRE(resultOf("true and false") == "false");
REQUIRE(resultOf("false and true") == "false");
REQUIRE(resultOf("false and false") == "false");
}
// TEST_CASE("and") {
// REQUIRE(resultOf("true and true") == "true");
// REQUIRE(resultOf("true and false") == "false");
// REQUIRE(resultOf("false and true") == "false");
// REQUIRE(resultOf("false and false") == "false");
// }

TEST_CASE("or") {
REQUIRE(resultOf("true or true") == "true");
REQUIRE(resultOf("true or false") == "true");
REQUIRE(resultOf("false or true") == "true");
REQUIRE(resultOf("false or false") == "false");
}
// TEST_CASE("or") {
// REQUIRE(resultOf("true or true") == "true");
// REQUIRE(resultOf("true or false") == "true");
// REQUIRE(resultOf("false or true") == "true");
// REQUIRE(resultOf("false or false") == "false");
// }

TEST_CASE("not") {
REQUIRE(resultOf("not(true)") == "false");
REQUIRE(resultOf("not(false)") == "true");
}
// TEST_CASE("not") {
// REQUIRE(resultOf("not(true)") == "false");
// REQUIRE(resultOf("not(false)") == "true");
// }

TEST_CASE("Empty blocks are true") {
REQUIRE(resultOf("{} or false") == "true");
}
// TEST_CASE("Empty blocks are true") {
// REQUIRE(resultOf("{} or false") == "true");
// }

TEST_CASE("0 is true") {
REQUIRE(resultOf("0 or false") == "true");
}
// TEST_CASE("0 is true") {
// REQUIRE(resultOf("0 or false") == "true");
// }

TEST_CASE("Empty strings are true") {
REQUIRE(resultOf("\"\" or false") == "true");
}
// TEST_CASE("Empty strings are true") {
// REQUIRE(resultOf("\"\" or false") == "true");
// }
102 changes: 51 additions & 51 deletions spec/e2e/def.spec.cpp
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
#include "spec/spec.h"

TEST_CASE("Fn set/call") {
REQUIRE(resultOf("x = fn (a) { a + 1 }; x(1)") == "2");
}
// TEST_CASE("Fn set/call") {
// REQUIRE(resultOf("x = fn (a) { a + 1 }; x(1)") == "2");
// }

TEST_CASE("Empty Fn") {
REQUIRE(resultOf("x = fn () {}; x()") == "{}");
}
// TEST_CASE("Empty Fn") {
// REQUIRE(resultOf("x = fn () {}; x()") == "{}");
// }

// TODO: Invalid number of arguments
//
// TEST_CASE("Error on invalid argument length") {
// REQUIRE(failure("x = fn () {}; x(1)"));
// }

TEST_CASE("Fn set/call in block") {
REQUIRE(resultOf(R"(
x = {
y = fn (a) { a + 1 }
}
// TEST_CASE("Fn set/call in block") {
// REQUIRE(resultOf(R"(
// x = {
// y = fn (a) { a + 1 }
// }

x.y(1)
)") == "2");
}
// x.y(1)
// )") == "2");
// }

TEST_CASE("Fn call within block") {
REQUIRE(resultOf(R"(
x = fn(a) {
foo = fn(b) { a + b }
}
// TEST_CASE("Fn call within block") {
// REQUIRE(resultOf(R"(
// x = fn(a) {
// foo = fn(b) { a + b }
// }

(x(1)).foo(1)
)") == "2");
}
// (x(1)).foo(1)
// )") == "2");
// }

// There was a time when we weren't passing params
// in the right order, every -other- time. Weird, huh?
TEST_CASE("Param ordering is correct every call") {
REQUIRE(resultOf(R"(
A = fn(a,b) {
when {
a eq 0 { false }
a eq 5 { true }
true { A(a+1, b) }
}
}
// // There was a time when we weren't passing params
// // in the right order, every -other- time. Weird, huh?
// TEST_CASE("Param ordering is correct every call") {
// REQUIRE(resultOf(R"(
// A = fn(a,b) {
// when {
// a eq 0 { false }
// a eq 5 { true }
// true { A(a+1, b) }
// }
// }

A(1, 0)
)") == "true");
}
// A(1, 0)
// )") == "true");
// }

TEST_CASE("Fns as arguments") {
REQUIRE(resultOf(R"(
do = fn (func, x) {
func(x)
}
// TEST_CASE("Fns as arguments") {
// REQUIRE(resultOf(R"(
// do = fn (func, x) {
// func(x)
// }

do(fn (x) { x + 1 }, 1)
)") == "2");
}
// do(fn (x) { x + 1 }, 1)
// )") == "2");
// }

TEST_CASE("Fn property get/set") {
REQUIRE(resultOf(R"(
x = fn (a) { a + 1 }
x.a = 1
x.a
)") == "1");
}
// TEST_CASE("Fn property get/set") {
// REQUIRE(resultOf(R"(
// x = fn (a) { a + 1 }
// x.a = 1
// x.a
// )") == "1");
// }
96 changes: 48 additions & 48 deletions spec/e2e/language.spec.cpp
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
#include "spec/spec.h"

TEST_CASE("Empty programs compile") {
REQUIRE(resultOf("") == "{}");
}
// TEST_CASE("Empty programs compile") {
// REQUIRE(resultOf("") == "{}");
// }

TEST_CASE("Bad programs do not compile") {
REQUIRE(failure("({)}"));
}
// TEST_CASE("Bad programs do not compile") {
// REQUIRE(failure("({)}"));
// }

TEST_CASE("Semicolons") {
REQUIRE(resultOf("x = 1; x") == "1");
}

TEST_CASE("Brackets") {
REQUIRE(resultOf("2 * (1 + 2)") == "6");
REQUIRE(resultOf("x = true; x").asBool() == true);
}

TEST_CASE("Variable redefinition not allowed") {
REQUIRE(failure("a = 1; a = 2"));
}

TEST_CASE("when") {
SECTION("runs code on true") {
REQUIRE(resultOf(R"(
when {
true { false }
}
)") == "false");
}

// TODO: Fix empty when case.
//
// SECTION("can be empty") {
// REQUIRE(resultOf("when {}") == "false");
// }

SECTION("runs the first true condition only") {
REQUIRE(resultOf(R"(
when {
false { 1 }
true { 2 }
false { 3 }
}
)") == "2");
}

SECTION("returns false if no conditions match") {
REQUIRE(resultOf(R"(
when {
false { true }
}
)") == "false");
}
}
// TEST_CASE("Brackets") {
// REQUIRE(resultOf("2 * (1 + 2)") == "6");
// }

// TEST_CASE("Variable redefinition not allowed") {
// REQUIRE(failure("a = 1; a = 2"));
// }

// TEST_CASE("when") {
// SECTION("runs code on true") {
// REQUIRE(resultOf(R"(
// when {
// true { false }
// }
// )") == "false");
// }

// // TODO: Fix empty when case.
// //
// // SECTION("can be empty") {
// // REQUIRE(resultOf("when {}") == "false");
// // }

// SECTION("runs the first true condition only") {
// REQUIRE(resultOf(R"(
// when {
// false { 1 }
// true { 2 }
// false { 3 }
// }
// )") == "2");
// }

// SECTION("returns false if no conditions match") {
// REQUIRE(resultOf(R"(
// when {
// false { true }
// }
// )") == "false");
// }
// }
34 changes: 17 additions & 17 deletions spec/e2e/list.spec.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#include "spec/spec.h"

TEST_CASE("List get/set") {
REQUIRE(resultOf("x = List(1, \"two\", true); x(1)") == "two");
}
// TEST_CASE("List get/set") {
// REQUIRE(resultOf("x = List(1, \"two\", true); x(1)") == "two");
// }

TEST_CASE("List.map") {
// TEST_CASE("List.map") {

SECTION("applies to every item of the List") {
REQUIRE(resultOf(R"(
l = List(1, 2, 3)
l.map(fn (i) { i + 1 })
)") == "List(2, 3, 4)");
}
// SECTION("applies to every item of the List") {
// REQUIRE(resultOf(R"(
// l = List(1, 2, 3)
// l.map(fn (i) { i + 1 })
// )") == "List(2, 3, 4)");
// }

SECTION("Fails if non-def is given") {
REQUIRE(failure(R"(
l = List(1, 2, 3)
l.map(false)
)"));
}
// SECTION("Fails if non-def is given") {
// REQUIRE(failure(R"(
// l = List(1, 2, 3)
// l.map(false)
// )"));
// }

}
// }

// TODO: List.reduce
//
Expand Down
Loading

0 comments on commit 67aa95e

Please sign in to comment.