test/test_source.rb in pdd-0.20.7 vs test/test_source.rb in pdd-0.20.8
- old
+ new
@@ -120,10 +120,29 @@
assert_equal '123', puzzle.props[:ticket]
end
end
end
+ def test_succeed_utf8_encoded_body
+ Dir.mktmpdir 'test' do |dir|
+ file = File.join(dir, 'a.txt')
+ File.write(
+ file,
+ "
+ * \x40todo #44 Привет, мир, мне кофе
+ * вторая линия
+ "
+ )
+ list = PDD::VerboseSource.new(file, PDD::Source.new(file, 'hey')).puzzles
+ assert_equal 1, list.size
+ puzzle = list.first
+ assert_equal '2-3', puzzle.props[:lines]
+ assert_equal 'Привет, мир, мне кофе вторая линия', puzzle.props[:body]
+ assert_equal '44', puzzle.props[:ticket]
+ end
+ end
+
def test_failing_on_incomplete_puzzle
Dir.mktmpdir 't5' do |dir|
file = File.join(dir, 'ff.txt')
File.write(
file,
@@ -139,11 +158,11 @@
end
def test_failing_on_broken_unicode
Dir.mktmpdir 'test' do |dir|
file = File.join(dir, 'xx.txt')
- File.write(file, ' * \x40todo #44 this is a broken unicode: ' + 0x92.chr)
+ File.write(file, " * \\x40todo #44 this is a broken unicode: #{0x92.chr}")
assert_raises PDD::Error do
stub_source_find_github_user(file, 'xx', &:puzzles)
end
end
end
@@ -207,10 +226,11 @@
git config user.name test_unknown
echo '\x40todo #1 this is the puzzle' > a.txt
git add a.txt
git commit --quiet -am 'first version'
")
+
stub_source_find_github_user(File.join(dir, 'a.txt')) do |source|
list = source.puzzles
assert_equal 1, list.size
puzzle = list.first
assert_equal '1-de87adc8', puzzle.props[:id]
@@ -235,10 +255,11 @@
git config user.name test
echo '\x40todo #1 this is the puzzle' > a.txt
git add a.txt
git commit --quiet -am 'first version'
")
+
stub_source_find_github_user(File.join(dir, 'a.txt')) do |source|
list = source.puzzles
assert_equal 1, list.size
puzzle = list.first
assert_equal '1-de87adc8', puzzle.props[:id]
@@ -262,10 +283,11 @@
git config user.name test
echo '\x40todo #1 this is the puzzle' > a.txt
git add a.txt
git commit --quiet -am 'first version'
")
+
stub_source_find_github_user(File.join(dir, 'a.txt')) do |source|
list = source.puzzles
assert_equal 1, list.size
puzzle = list.first
assert_equal '@yegor256', puzzle.props[:author]
@@ -284,9 +306,10 @@
echo 'hi' > a.txt
git add a.txt
git commit --quiet -am 'first version'
echo '\x40todo #1 this is a puzzle uncommitted' > a.txt
")
+
stub_source_find_github_user(File.join(dir, 'a.txt')) do |source|
list = source.puzzles
assert_equal 1, list.size
puzzle = list.first
assert_nil puzzle.props[:email]