]> jaekl.net Git - quanlib.git/commitdiff
Add unit test for Author, and new testcase for Book
authorChris Jaekl <chris@jaekl.net>
Thu, 20 Jun 2024 17:54:39 +0000 (13:54 -0400)
committerChris Jaekl <chris@jaekl.net>
Thu, 20 Jun 2024 17:54:39 +0000 (13:54 -0400)
test/author_test.rb [new file with mode: 0644]
test/book_test.rb

diff --git a/test/author_test.rb b/test/author_test.rb
new file mode 100644 (file)
index 0000000..088d4d0
--- /dev/null
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require "test_helper"
+require "author"
+
+class AuthorTest < Minitest::Test
+  def test_that_initialization_values_are_reflected_in_the_created_object
+    grouping = "Daniel Defoe"
+    reading_order = "Daniel Defoe"
+    sort_order = "Defoe, Daniel"
+
+    author = Author.new(grouping, reading_order, sort_order)
+
+    assert_equal grouping, author.grouping
+    assert_equal reading_order, author.reading_order
+    assert_equal sort_order, author.sort_order
+  end
+
+  def test_that_sort_order_is_auto_inferred
+    grouping = "DanielDefoe"
+    reading_order = "Daniel Defoe"
+
+    author = Author.new(grouping, reading_order, nil)
+
+    assert_equal "Defoe, Daniel", author.sort_order
+  end
+
+  def test_inspect
+    author = Author.new("DanielDefoe", "Daniel Defoe", "Defoe, Daniel")
+
+    expected = '(Author: grouping="DanielDefoe" reading_order="Daniel Defoe" sort_order="Defoe, Daniel")'
+
+    assert_equal expected, author.inspect
+    assert_equal expected, author.to_s
+  end
+end
index de3227897be674ba1bf727a58404eafec7d3d173..90c918a13f05505c4316ca3567d745178bafff3a 100644 (file)
@@ -15,4 +15,17 @@ class BookTest < Minitest::Test
       assert_equal false, Book.can_handle?("sample.#{extension}")
     end
   end
+
+  def test_grouping_for_title
+    data = {
+      "A Study in Scarlet" => "A_Study_in_Scarlet",
+      "That'll be the Day" => "That-ll_be_the_Day",
+      "Banzai!" => "Banzai-",
+      "#tweet_cute" => "-tweet_cute",
+    }
+
+    data.each do |input, expected|
+      assert_equal expected, Book.grouping_for_title(input)
+    end
+  end
 end