test/test_source.rb in pdd-0.20.8 vs test/test_source.rb in pdd-0.21.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2014-2021 Yegor Bugayenko
+# Copyright (c) 2014-2022 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -23,11 +23,11 @@
require_relative '../lib/pdd'
require_relative '../lib/pdd/sources'
# Source test.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
-# Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
+# Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
# License:: MIT
class TestSource < Minitest::Test
def test_parsing
Dir.mktmpdir 'test' do |dir|
file = File.join(dir, 'a.txt')
@@ -44,12 +44,13 @@
)
stub_source_find_github_user(file, 'hey') do |source|
list = source.puzzles
assert_equal 2, list.size
puzzle = list.first
- assert_equal '2-3', puzzle.props[:lines]
- assert_equal 'привет, how are you doing?', puzzle.props[:body]
+ assert_equal '2-4', puzzle.props[:lines]
+ assert_equal 'привет, how are you doing? -something else', \
+ puzzle.props[:body]
assert_equal '44', puzzle.props[:ticket]
assert puzzle.props[:author].nil?
assert puzzle.props[:email].nil?
assert puzzle.props[:time].nil?
end
@@ -76,49 +77,58 @@
assert_equal '56', puzzle.props[:ticket]
end
end
end
- def test_failing_on_invalid_puzzle
+ def test_multiple_puzzles_single_comment_block
Dir.mktmpdir 'test' do |dir|
file = File.join(dir, 'a.txt')
File.write(
file,
"
- * \x40todo #44 this is an incorrectly formatted puzzle,
- * with a second line without a leading space
+ /*
+ * \x40todo #1 First one with
+ * a few lines
+ * \x40todo #1 Second one also
+ * with a few lines
+ */
"
)
- error = assert_raises PDD::Error do
- stub_source_find_github_user(file, 'hey', &:puzzles)
+ stub_source_find_github_user(file, 'hey') do |source|
+ PDD.opts = nil
+ assert_equal 2, source.puzzles.size
+ puzzle = source.puzzles.last
+ assert_equal '5-6', puzzle.props[:lines]
+ assert_equal 'Second one also with a few lines', puzzle.props[:body]
+ assert_equal '1', puzzle.props[:ticket]
end
- assert !error.message.index('Space expected').nil?
end
end
def test_succeed_despite_bad_puzzles
Dir.mktmpdir 'test' do |dir|
file = File.join(dir, 'a.txt')
File.write(
file,
"
- * \x40todo #44 this is an incorrectly formatted puzzle,
+ * \x40todo #44 this is a correctly formatted puzzle,
* with a second line without a leading space
Another badly formatted puzzle
- * \x40todo this puzzle misses ticket name/number
+ * \x40todo this bad puzzle misses ticket name/number
Something else
* \x40todo #123 This puzzle is correctly formatted
"
)
PDD.opts = { 'skip-errors' => true }
stub_source_find_github_user(file, 'hey') do |source|
list = source.puzzles
PDD.opts = nil
- assert_equal 1, list.size
+ assert_equal 2, list.size
puzzle = list.first
- assert_equal '7-7', puzzle.props[:lines]
- assert_equal 'This puzzle is correctly formatted', puzzle.props[:body]
- assert_equal '123', puzzle.props[:ticket]
+ assert_equal '2-3', puzzle.props[:lines]
+ assert_equal 'this is a correctly formatted puzzle, with a second ' \
+ 'line without a leading space', puzzle.props[:body]
+ assert_equal '44', puzzle.props[:ticket]
end
end
end
def test_succeed_utf8_encoded_body