#!/bin/sh

. ../../../scripts/test-utils.sh

fpp_syntax=../../../bin/fpp-syntax

run_test()
{
  args=$1
  infile=$2
  if test -n "$3"
  then
    outfile=$3
  else
    outfile=$infile
  fi
  $fpp_syntax $args $infile.fpp 2>&1 | remove_path_prefix > $outfile.out.txt
  diff -u $outfile.ref.txt $outfile.out.txt > $outfile.diff.txt 2>&1
}

comments()
{
  run_test "" comments
}

empty()
{
  run_test -a empty
}

escaped_strings()
{
  run_test -a escaped-strings
}

include_component()
{
  run_test -ia include-component
}

include_constant_1()
{
  run_test -ia include-constant-1
}

include_cycle_1()
{
  run_test -i cycle-1 include-cycle-1
}

include_cycle_2()
{
  run_test -i cycle-2 include-cycle-2
}

include_missing_file()
{
  run_test -i include-missing-file
}

include_module()
{
  run_test -ia include-module
}

include_parse_error()
{
  run_test -i include-parse-error
}

include_parent_dir()
{
  run_test -ia subdir/include-parent-dir
}

include_subdir()
{
  run_test -ia include-subdir
}

include_topology()
{
  run_test -ia include-topology
}

parse_error()
{
  run_test "" parse-error
}

syntax()
{
  run_test "" syntax
}

syntax_kwd_names()
{
  run_test "" syntax-kwd-names
}

syntax_ast()
{
  run_test -a syntax syntax-ast
}

syntax_include_ast()
{
  run_test -ia syntax syntax-include-ast
}

syntax_stdin()
{
  cat syntax.fpp | $fpp_syntax -ia > syntax-stdin.out.txt
  diff -u syntax-stdin.ref.txt syntax-stdin.out.txt > syntax-stdin.diff.txt 2>&1
}

two_input_files()
{
  $fpp_syntax -ia include-module.fpp include-component.fpp 2>&1 > two-input-files.out.txt
  diff -u two-input-files.ref.txt two-input-files.out.txt > two-input-files.diff.txt 2>&1
}

tests="
comments
empty
escaped_strings
include_component
include_constant_1
include_cycle_1
include_cycle_2
include_missing_file
include_module
include_parent_dir
include_parse_error
include_subdir
include_topology
parse_error
syntax
syntax_kwd_names
syntax_ast
syntax_include_ast
syntax_stdin
two_input_files
"

run_suite $tests
