1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-30 01:23:04 +03:00
guide/back/tests/MergeSpec.hs

77 lines
2.1 KiB
Haskell
Raw Normal View History

2016-08-21 17:45:46 +03:00
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module MergeSpec (tests) where
-- Shared imports
import Imports
2016-08-21 17:45:46 +03:00
-- Text
2018-09-02 01:03:48 +03:00
import qualified Data.Text as T
2016-08-21 17:45:46 +03:00
-- Testing
import Test.Hspec
import Test.Hspec.QuickCheck
import Test.QuickCheck
import Data.Text.Arbitrary ()
2017-07-01 23:55:54 +03:00
import Guide.Diff.Merge
2016-08-21 17:45:46 +03:00
tests :: Spec
tests = describe "merging" $ do
-- <from>: <variant A>+<variant B> = <merged>
describe "simple cases" $ do
describe "A: A+A = A" $
prop "QuickCheck" $ \(M a) ->
merge a a a === a
describe "A: B+B = B" $
prop "QuickCheck" $ \(M a) (M b) ->
merge a b b === b
describe "A: A+B = B" $
prop "QuickCheck" $ \(M a) (M b) ->
merge a a b === b
describe "replacing" $ do
it "different words" $ do
merge "a b c" "x b c" "a b y" `shouldBe` "x b y"
it "words separated by /s" $ do
merge "a/b/c" "x/b/c" "a/b/y" `shouldBe` "x/b/y"
it "punctuation" $ do
merge "a,b,c" "a,b!c" "a?b,c" `shouldBe` "a?b!c"
it "words with similar words" $ do
merge "foobar" "foobir" "xoobar" `shouldBe` "foobir"
describe "inserting" $ do
it "words in different but near places" $ do
merge "f x" "A B C f x" "f d b e x" `shouldBe` "A B C f d b e x"
it "words from different sides" $ do
merge "x" "foo x" "x bar" `shouldBe` "foo x bar"
merge "x" "a foo x" "x bar" `shouldBe` "a foo x bar"
it "words and punctuation in random places" $ do
merge "a b,c d" " a x/b, c d" "a b,c d e" `shouldBe` " a x/b, c d e"
it "several words" $ do
merge "a b c d" "a a a b c d e" "a b c e d" `shouldBe` "a a a b c e d e"
describe "deleting" $ do
it "words" $ do
merge "a B c D" "a c D" "a B c" `shouldBe` "a c"
describe "tokens" $ do
it "links aren't merged" $ do
merge "http://a/b/c" "http://x/b/c" "http://a/b/y"
`shouldBe` "http://x/b/c"
newtype M = M Text
deriving (Eq, Ord)
instance Show M where
show (M x) = show x
instance Arbitrary M where
shrink (M x) = map M (shrink x)
arbitrary = M <$> oneof [
return "",
T.singleton <$> elements "abc123",
T.singleton <$> elements " .,()*+/",
arbitrary ]