UIStringParser.purs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module Test.UIStringParser
  2. ( main
  3. )
  4. where
  5. import Data.Date (Month(..))
  6. import Data.Either (Either(..))
  7. import Effect (Effect)
  8. import LinkedIn.UIElements.Parser (durationP, monthYearP, timeSpanP, uiStringDurationP, uiStringdotSeparatedP)
  9. import LinkedIn.UIElements.Types (Duration(..), TimeSpan(..), UIString(..))
  10. import Parsing (runParser)
  11. import Prelude (Unit, discard)
  12. import Test.Assert (assertEqual)
  13. import Test.Utils (toMonthYear')
  14. testMonthYearParser ∷ Effect Unit
  15. testMonthYearParser = do
  16. assertEqual {
  17. actual: run "fév. 2004",
  18. expected: Right(toMonthYear' February 2004)
  19. }
  20. assertEqual {
  21. actual: run "juin 2012",
  22. expected: Right(toMonthYear' June 2012)
  23. }
  24. where run s = runParser s monthYearP
  25. testTimeSpanParser ∷ Effect Unit
  26. testTimeSpanParser = do
  27. assertEqual {
  28. actual: run "juin 2012 - aujourd’hui",
  29. expected: Right(TimeSpanToToday (toMonthYear' June 2012))
  30. }
  31. assertEqual {
  32. actual: run "juin 2012 - mai 2021",
  33. expected: Right(TimeSpanBounded (toMonthYear' June 2012) (toMonthYear' May 2021))
  34. }
  35. where run s = runParser s timeSpanP
  36. testDurationParser ∷ Effect Unit
  37. testDurationParser = do
  38. assertEqual {
  39. actual: run "2 ans 3 mois",
  40. expected: Right(YearsMonth 2 3)
  41. }
  42. assertEqual {
  43. actual: run "1 an 3 mois",
  44. expected: Right(YearsMonth 1 3)
  45. }
  46. assertEqual {
  47. actual: run "3 mois",
  48. expected: Right(Months 3)
  49. }
  50. assertEqual {
  51. actual: run "3 ans",
  52. expected: Right(Years 3)
  53. }
  54. assertEqual {
  55. actual: run "1 an",
  56. expected: Right(Years 1)
  57. }
  58. where run s = runParser s durationP
  59. testUIParserDuration ∷ Effect Unit
  60. testUIParserDuration = do
  61. assertEqual {
  62. actual: run "2 ans 3 mois",
  63. expected: Right(UIStringDuration (YearsMonth 2 3))
  64. }
  65. where run s = runParser s uiStringDurationP
  66. testUIParserDotSeparated ∷ Effect Unit
  67. testUIParserDotSeparated = do
  68. assertEqual {
  69. actual: run "2 ans 3 mois · some text",
  70. expected: Right(UIStringDotSeparated (UIStringDuration (YearsMonth 2 3)) (UIStringPlain "some text"))
  71. }
  72. assertEqual {
  73. actual: run "· Boulogne-Billancourt, Île-de-France, France",
  74. expected: Right(UIStringDotSeparated (UIStringPlain "") (UIStringPlain "Boulogne-Billancourt, Île-de-France, France"))
  75. }
  76. where run s = runParser s uiStringdotSeparatedP
  77. main :: Effect Unit
  78. main = do
  79. testMonthYearParser
  80. testTimeSpanParser
  81. testDurationParser
  82. testUIParserDuration
  83. testUIParserDotSeparated