From 9106fb07a47dd72e0399e2f9cecf86fc16c2339d Mon Sep 17 00:00:00 2001 From: aonemd Date: Sat, 3 Dec 2016 04:03:23 +0200 Subject: [PATCH] Add unit tests for Changit::Lexer --- test/lexer_test.rb | 28 ++++++++++++++++++++++++++++ test/test_helper.rb | 8 ++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/lexer_test.rb diff --git a/test/lexer_test.rb b/test/lexer_test.rb new file mode 100644 index 0000000..c3dd15a --- /dev/null +++ b/test/lexer_test.rb @@ -0,0 +1,28 @@ +require 'test_helper' +require 'changit/lexer' +require 'changit/lexer/section_token' + +class LexerTest < Minitest::Test + def test_tokenize + tokens = lexer.tokens + + assert_kind_of Array, tokens + refute_empty tokens + assert_equal tokens.size, lexer.original_expression.each_line.count + end + + def test_to_hash + token_hash = lexer.token_hash + + assert_kind_of Hash, token_hash + refute_empty token_hash + assert_kind_of_array Changit::Lexer::SectionToken, token_hash.keys + end + + private + + def lexer + config = "[user]\n\tname = testname\n\temail = testmail@domain.com\n[core]\n\teditor = vim\n[color]\n\tui = true\n[rebase]\n\tautosquash = true\n".freeze + Changit::Lexer.new(config) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 63eea4f..49deccd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,11 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'minitest/autorun' + +# some unorganized helpers + +def assert_kind_of_array(kind, arr) + arr.all? do |e| + assert_kind_of kind, e + end +end