Skip to content
This repository has been archived by the owner on Jun 6, 2020. It is now read-only.

Commit

Permalink
Implemented tests
Browse files Browse the repository at this point in the history
- compiler.print_error
- compiler.get_keyword
- compiler.get_line
- compiler.get_condition
  • Loading branch information
G. Roggemans committed Jun 14, 2016
1 parent f4fd85d commit e880bd1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/compiler.bash
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ compiler.parse_file() {
# Extract the condition from a line
compiler.get_condition() {
local cmd="$1"
local sed_string="s/^$EC_COMMENT$EC_PROMPT if//;\
s/^$EC_COMMENT$EC_PROMPT elif//;\
s/; then//"
local sed_string="s/^$EC_COMMENT$EC_PROMPT if //;\
s/^$EC_COMMENT$EC_PROMPT elif //;\
s/; then//;\
s/;then//"

sed "$sed_string" <<< "$cmd"
}
Expand Down
43 changes: 32 additions & 11 deletions test/compiler.bats
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,29 @@ teardown() {
[ "${lines[1]}" = "| test/file-name:1" ]
[ "${lines[2]}" = "| 'the troubled line'" ]
[ "${lines[3]}" = "> Error message" ]
}

@test "compiler.get_keyword gets keyword" {
skip "No test implementation"
local file="test/file-name"
local file_name="file-name"
local line_nr=1
local line="the troubled line"
run compiler.print_error "Error message"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Syntax error in 'file-name' at line nr 1:" ]
[ "${lines[1]}" = "| test/file-name:1" ]
[ "${lines[2]}" = "| 'the troubled line'" ]
[ "${lines[3]}" = "> Error message" ]
}

@test "compiler.get_keyword gets keyword" {
skip "No test implementation"
}

@test "compiler.get_line strips keyword" {
skip "No test implementation"
run compiler.get_keyword "comment key_word other stuff here"
[ "$status" -eq 0 ]
[ "$output" = "key_word" ]
}

@test "compiler.get_line strips keyword" {
skip "No test implementation"
@test "compiler.get_line gets line (strips keyword)" {
run compiler.get_line "comment key_word other stuff here"
[ "$status" -eq 0 ]
[ "$output" = "other stuff here" ]
}

@test "compiler.compile compiles a file" {
Expand All @@ -78,7 +85,21 @@ teardown() {
}

@test "compiler.get_condition gets if/elif condition" {
skip "No test implementation"
run compiler.get_condition "#_> if [ if ]"
[ "$status" -eq 0 ]
[ "$output" = "[ if ]" ]

run compiler.get_condition "#_> if if"
[ "$status" -eq 0 ]
[ "$output" = "if" ]

run compiler.get_condition "#_> elif [ elif ]"
[ "$status" -eq 0 ]
[ "$output" = "[ elif ]" ]

run compiler.get_condition "#_> if [ then ]; then"
[ "$status" -eq 0 ]
[ "$output" = "[ then ]" ]
}

@test "compiler.parse_if parses if/elif" {
Expand Down

0 comments on commit e880bd1

Please sign in to comment.