2015-12-17 21:08:47 +03:00
|
|
|
module RangeSpec where
|
|
|
|
|
2016-09-15 00:45:23 +03:00
|
|
|
import Prologue
|
2015-12-17 21:08:47 +03:00
|
|
|
import Range
|
2016-09-15 00:45:23 +03:00
|
|
|
import Test.Hspec (Spec, describe, it, parallel)
|
|
|
|
import Test.Hspec.Expectations.Pretty
|
2015-12-17 21:08:47 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2016-01-05 18:38:51 +03:00
|
|
|
spec = parallel $ do
|
|
|
|
describe "rangesAndWordsFrom" $ do
|
2015-12-17 21:08:47 +03:00
|
|
|
it "should produce no ranges for the empty string" $
|
2015-12-18 23:03:36 +03:00
|
|
|
rangesAndWordsFrom 0 mempty `shouldBe` []
|
2015-12-17 21:08:47 +03:00
|
|
|
|
|
|
|
it "should produce no ranges for whitespace" $
|
|
|
|
rangesAndWordsFrom 0 " \t\n " `shouldBe` []
|
|
|
|
|
|
|
|
it "should produce a list containing the range of the string for a single-word string" $
|
|
|
|
rangesAndWordsFrom 0 "word" `shouldBe` [ (Range 0 4, "word") ]
|
|
|
|
|
|
|
|
it "should produce a list of ranges for whitespace-separated words" $
|
|
|
|
rangesAndWordsFrom 0 "wordOne wordTwo" `shouldBe` [ (Range 0 7, "wordOne"), (Range 8 15, "wordTwo") ]
|
|
|
|
|
|
|
|
it "should skip multiple whitespace characters" $
|
|
|
|
rangesAndWordsFrom 0 "a b" `shouldBe` [ (Range 0 1, "a"), (Range 3 4, "b") ]
|
|
|
|
|
|
|
|
it "should skip whitespace at the start" $
|
|
|
|
rangesAndWordsFrom 0 " a b" `shouldBe` [ (Range 2 3, "a"), (Range 4 5, "b") ]
|
|
|
|
|
|
|
|
it "should skip whitespace at the end" $
|
|
|
|
rangesAndWordsFrom 0 "a b " `shouldBe` [ (Range 0 1, "a"), (Range 2 3, "b") ]
|
|
|
|
|
|
|
|
it "should produce ranges offset by its start index" $
|
|
|
|
rangesAndWordsFrom 100 "a b" `shouldBe` [ (Range 100 101, "a"), (Range 102 103, "b") ]
|