Added tests for the parser
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				ci/woodpecker/push/workflow Pipeline was successful
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	ci/woodpecker/push/workflow Pipeline was successful
				
			This commit is contained in:
		@@ -1,7 +1,16 @@
 | 
			
		||||
#include "value.hpp"
 | 
			
		||||
#include <catch2/catch_test_macros.hpp>
 | 
			
		||||
#include <lex.hpp>
 | 
			
		||||
#include <parse.hpp>
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
T pop_and_front(deque<T> &dq) {
 | 
			
		||||
    T t = dq.front();
 | 
			
		||||
    dq.pop_front();
 | 
			
		||||
    return t;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_CASE("Lexer lexes doubles correctly", "[Lexer]") {
 | 
			
		||||
    
 | 
			
		||||
    SECTION("double and negative syntax") {
 | 
			
		||||
@@ -19,3 +28,25 @@ TEST_CASE("Lexer lexes doubles correctly", "[Lexer]") {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_CASE("Parser parses correctly", "[Parser]") {
 | 
			
		||||
    SECTION("hello world") {
 | 
			
		||||
        Parser p (Lexer("(print \"hello world\")"));
 | 
			
		||||
        auto dq = get<List>(*p.next()).list;
 | 
			
		||||
        REQUIRE(get<Symbol>(pop_and_front(dq)).value == "print");
 | 
			
		||||
        REQUIRE(get<String>(pop_and_front(dq)).value == "hello world");
 | 
			
		||||
    }
 | 
			
		||||
    SECTION("doubles") {
 | 
			
		||||
        Parser p (Lexer("(1.0 0.1 -.1 -1. . - -. .-)"));
 | 
			
		||||
        auto dq = get<List>(*p.next()).list;
 | 
			
		||||
        REQUIRE(get<Double>(pop_and_front(dq)).value == 1.0);
 | 
			
		||||
        REQUIRE(get<Double>(pop_and_front(dq)).value == 0.1);
 | 
			
		||||
        REQUIRE(get<Double>(pop_and_front(dq)).value == -0.1);
 | 
			
		||||
        REQUIRE(get<Double>(pop_and_front(dq)).value == -1.0);
 | 
			
		||||
        REQUIRE(get<Symbol>(pop_and_front(dq)).value == ".");
 | 
			
		||||
        REQUIRE(get<Symbol>(pop_and_front(dq)).value == "-");
 | 
			
		||||
        REQUIRE(get<Symbol>(pop_and_front(dq)).value == "-.");
 | 
			
		||||
        REQUIRE(get<Symbol>(pop_and_front(dq)).value == ".-");
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user