This commit is contained in:
@@ -13,6 +13,8 @@ steps:
|
|||||||
- name: test
|
- name: test
|
||||||
image: ubuntu
|
image: ubuntu
|
||||||
commands:
|
commands:
|
||||||
# TODO: Probably make actual tests at some point
|
# Automated tests, this should not fail
|
||||||
|
- ./test
|
||||||
|
# Manual test, you can see the output of this in woodpecker
|
||||||
- echo "(print 42)" | ./build/main
|
- echo "(print 42)" | ./build/main
|
||||||
# TODO: add publish step, when we're at a working state.
|
# TODO: add publish step, when we're at a working state.
|
@@ -1,10 +1,30 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
project(lispy_stuff)
|
project(lispy_stuff)
|
||||||
|
|
||||||
|
# we'll use catch2 as testing library.
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
Catch2
|
||||||
|
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||||
|
GIT_TAG v3.8.1
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(Catch2)
|
||||||
|
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
|
||||||
|
include(Catch)
|
||||||
|
|
||||||
set(HEADER_FILES src/include/lex.hpp)
|
set(HEADER_FILES src/include/lex.hpp)
|
||||||
set(SOURCE_FILES src/main.cpp src/lex.cpp)
|
set(SOURCE_FILES src/lex.cpp)
|
||||||
|
|
||||||
|
# we're not actually shipping a library yet,
|
||||||
|
# this is so we don't have to compile twice for main and tests.
|
||||||
|
add_library(libmash STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||||
|
target_include_directories(libmash PUBLIC src/include/)
|
||||||
|
|
||||||
add_executable(main ${SOURCE_FILES} ${HEADER_FILES})
|
# Main target
|
||||||
|
add_executable(main src/main.cpp)
|
||||||
|
target_link_libraries(main libmash)
|
||||||
|
|
||||||
|
# tests
|
||||||
|
add_executable(test src/tests/test.cpp)
|
||||||
|
target_link_libraries(test PRIVATE libmash Catch2::Catch2WithMain)
|
||||||
|
|
||||||
target_include_directories(main PRIVATE src/include/)
|
|
21
src/tests/test.cpp
Normal file
21
src/tests/test.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <lex.hpp>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
TEST_CASE("Lexer lexes doubles correctly", "[Lexer]") {
|
||||||
|
|
||||||
|
SECTION("double and negative syntax") {
|
||||||
|
Lexer l("(1.0 0.1 -.1 -1. . - -. .-)");
|
||||||
|
REQUIRE(l.next() == Token({OpenParen}));
|
||||||
|
REQUIRE(l.next() == Token({Double, 1.0}));
|
||||||
|
REQUIRE(l.next() == Token({Double, 0.1}));
|
||||||
|
REQUIRE(l.next() == Token({Double, -0.1}));
|
||||||
|
REQUIRE(l.next() == Token({Double, -1.0}));
|
||||||
|
REQUIRE(l.next() == Token({Symbol, "."}));
|
||||||
|
REQUIRE(l.next() == Token({Symbol, "-"}));
|
||||||
|
REQUIRE(l.next() == Token({Symbol, "-."}));
|
||||||
|
REQUIRE(l.next() == Token({Symbol, ".-"}));
|
||||||
|
REQUIRE(l.next() == Token({CloseParen}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user