Skip to content

Commit

Permalink
Add unit tests for Changit::Lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
aonemd committed Dec 3, 2016
1 parent 4483515 commit 9106fb0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/lexer_test.rb
Original file line number Diff line number Diff line change
@@ -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 = [email protected]\n[core]\n\teditor = vim\n[color]\n\tui = true\n[rebase]\n\tautosquash = true\n".freeze
Changit::Lexer.new(config)
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9106fb0

Please sign in to comment.