You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scalatest-test/src/test/scala/org/scalatest/ShouldContainElementSpec.scala
+24-59Lines changed: 24 additions & 59 deletions
Original file line number
Diff line number
Diff line change
@@ -1732,132 +1732,97 @@ class ShouldContainElementSpec extends FunSpec with PropertyChecks with ReturnsN
1732
1732
valcaught1= intercept[TestFailedException] {
1733
1733
HashMap("one"->1, "two"->2) should contain ("three"->3)
1734
1734
}
1735
-
assert(caught1.getMessage.startsWith("Map("))
1736
-
assert(caught1.getMessage.endsWith(") did not contain element (three,3)"))
1735
+
assert(caught1.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (three,3)"))
1737
1736
}
1738
1737
1739
1738
it("should throw TestFailedException if contains the specified element when used with not") {
1740
1739
1741
1740
valcaught1= intercept[TestFailedException] {
1742
1741
HashMap("one"->1, "two"->2) should (not contain ("two"->2))
1743
1742
}
1744
-
assert(caught1.getMessage.startsWith("Map("))
1745
-
assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1746
-
1747
-
1743
+
assert(caught1.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
1744
+
1748
1745
valcaught2= intercept[TestFailedException] {
1749
1746
HashMap("one"->1, "two"->2) should not (contain ("two"->2))
1750
1747
}
1751
-
assert(caught1.getMessage.startsWith("Map("))
1752
-
assert(caught1.getMessage.endsWith(" contained element (two,2)"))
1753
-
1748
+
assert(caught2.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
1754
1749
1755
1750
valcaught3= intercept[TestFailedException] {
1756
1751
HashMap("one"->1, "two"->2) should not contain ("two"->2)
1757
1752
}
1758
-
assert(caught1.getMessage.startsWith("Map("))
1759
-
assert(caught1.getMessage.endsWith(" contained element (two,2)"))
1753
+
assert(caught3.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
1760
1754
}
1761
1755
1762
1756
it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-and expression") {
1763
1757
1764
1758
valcaught1= intercept[TestFailedException] {
1765
1759
HashMap("one"->1, "two"->2) should { contain ("five"->5) and (contain ("two"->2)) }
1766
1760
}
1767
-
assert(caught1.getMessage.startsWith("Map("))
1768
-
assert(caught1.getMessage.endsWith(" did not contain element (five,5)"))
1769
-
1761
+
assert(caught1.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (five,5)"))
1762
+
1770
1763
valcaught2= intercept[TestFailedException] {
1771
1764
HashMap("one"->1, "two"->2) should ((contain ("five"->5)) and (contain ("two"->2)))
1772
1765
}
1773
-
assert(caught1.getMessage.startsWith("Map("))
1774
-
assert(caught1.getMessage.endsWith(" did not contain element (five,5)"))
1775
-
1766
+
assert(caught2.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (five,5)"))
1767
+
1776
1768
valcaught3= intercept[TestFailedException] {
1777
1769
HashMap("one"->1, "two"->2) should (contain ("five"->5) and contain ("two"->2))
1778
1770
}
1779
-
assert(caught1.getMessage.startsWith("Map("))
1780
-
assert(caught1.getMessage.endsWith(" did not contain element (five,5)"))
1771
+
assert(caught3.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (five,5)"))
1781
1772
}
1782
1773
1783
1774
it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-or expression") {
1784
1775
1785
1776
valcaught1= intercept[TestFailedException] {
1786
1777
HashMap("one"->1, "two"->2) should { contain ("fifty five"->55) or (contain ("twenty two"->22)) }
1787
1778
}
1788
-
assert(caught1.getMessage.startsWith("Map("))
1789
-
assert(caught1.getMessage.contains(") did not contain element (fifty five,55), and Map("))
1790
-
assert(caught1.getMessage.endsWith(") did not contain element (twenty two,22)"))
1791
-
1779
+
assert(caught1.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (fifty five,55), and "+Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (twenty two,22)"))
1780
+
1792
1781
valcaught2= intercept[TestFailedException] {
1793
1782
HashMap("one"->1, "two"->2) should ((contain ("fifty five"->55)) or (contain ("twenty two"->22)))
1794
1783
}
1795
-
//assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1796
-
assert(caught1.getMessage.startsWith("Map("))
1797
-
assert(caught1.getMessage.contains(") did not contain element (fifty five,55), and Map("))
1798
-
assert(caught1.getMessage.endsWith(") did not contain element (twenty two,22)"))
1799
-
1784
+
assert(caught2.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (fifty five,55), and "+Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (twenty two,22)"))
1785
+
1800
1786
valcaught3= intercept[TestFailedException] {
1801
1787
HashMap("one"->1, "two"->2) should (contain ("fifty five"->55) or contain ("twenty two"->22))
1802
1788
}
1803
-
//assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1804
-
assert(caught1.getMessage.startsWith("Map("))
1805
-
assert(caught1.getMessage.contains(") did not contain element (fifty five,55), and Map("))
1806
-
assert(caught1.getMessage.endsWith(") did not contain element (twenty two,22)"))
1789
+
assert(caught3.getMessage == (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (fifty five,55), and "+Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (twenty two,22)"))
1807
1790
}
1808
1791
1809
1792
it("should throw an TestFailedException when map contains specified element and used in a logical-and expression with not") {
1810
1793
1811
1794
valcaught1= intercept[TestFailedException] {
1812
1795
HashMap("one"->1, "two"->2) should { not { contain ("three"->3) } and not { contain ("two"->2) }}
1813
1796
}
1814
-
//assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1815
-
assert(caught1.getMessage.startsWith("Map("))
1816
-
assert(caught1.getMessage.contains(") did not contain element (three,3), but Map("))
1817
-
assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1818
-
1797
+
assert(caught1.getMessage === (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (three,3), but "+Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
1798
+
1819
1799
valcaught2= intercept[TestFailedException] {
1820
1800
HashMap("one"->1, "two"->2) should ((not contain ("three"->3)) and (not contain ("two"->2)))
1821
1801
}
1822
-
//assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1823
-
assert(caught1.getMessage.startsWith("Map("))
1824
-
assert(caught1.getMessage.contains(") did not contain element (three,3), but Map("))
1825
-
assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1826
-
1802
+
assert(caught2.getMessage === (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (three,3), but "+Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
1803
+
1827
1804
valcaught3= intercept[TestFailedException] {
1828
1805
HashMap("one"->1, "two"->2) should (not contain ("three"->3) and not contain ("two"->2))
1829
1806
}
1830
-
//assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1831
-
assert(caught1.getMessage.startsWith("Map("))
1832
-
assert(caught1.getMessage.contains(") did not contain element (three,3), but Map("))
1833
-
assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1807
+
assert(caught3.getMessage === (Prettifier.default(HashMap("one"->1, "two"->2)) +" did not contain element (three,3), but "+Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
1834
1808
}
1835
1809
1836
1810
it("should throw an TestFailedException when map contains specified element and used in a logical-or expression with not") {
1837
1811
1838
1812
valcaught1= intercept[TestFailedException] {
1839
1813
HashMap("one"->1, "two"->2) should { not { contain ("two"->2) } or not { contain ("two"->2) }}
1840
1814
}
1841
-
//assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1842
-
assert(caught1.getMessage.startsWith("Map("))
1843
-
assert(caught1.getMessage.contains(" contained element (two,2), and Map("))
1844
-
assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1845
-
1815
+
assert(caught1.getMessage === (Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2), and "+Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
1816
+
1846
1817
valcaught2= intercept[TestFailedException] {
1847
1818
HashMap("one"->1, "two"->2) should ((not contain ("two"->2)) or (not contain ("two"->2)))
1848
1819
}
1849
-
//assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1850
-
assert(caught1.getMessage.startsWith("Map("))
1851
-
assert(caught1.getMessage.contains(" contained element (two,2), and Map("))
1852
-
assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1820
+
assert(caught2.getMessage === (Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2), and "+Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
1853
1821
1854
1822
valcaught3= intercept[TestFailedException] {
1855
1823
HashMap("one"->1, "two"->2) should (not contain ("two"->2) or not contain ("two"->2))
1856
1824
}
1857
-
//assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1858
-
assert(caught1.getMessage.startsWith("Map("))
1859
-
assert(caught1.getMessage.contains(" contained element (two,2), and Map("))
1860
-
assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1825
+
assert(caught3.getMessage === (Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2), and "+Prettifier.default(HashMap("one"->1, "two"->2)) +" contained element (two,2)"))
0 commit comments