summaryrefslogtreecommitdiff
path: root/haskell/examples/testdiff.hs
blob: 7e20dc50bf8cbb8fd10384c99b21b12509a77d54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Lazy as L
import Data.VCDIFF
import Text.XXD

source :: L.ByteString
source = "It could be said that Joe was here. I don't know what to do about it."

patched :: L.ByteString
patched = "It could be said that Joe, the magnificent, was here.  I don't know what to do about it."

delta :: Result VCDIFF
delta = computeDiff defaultConfig source patched

main = do
    mapM_ putStrLn $ xxd2 0 (L.toStrict source)
    putStrLn ""
    mapM_ putStrLn $ xxd2 0 (L.toStrict patched)
    putStrLn ""
    case delta of
        Result δ@(VCDIFF d) me -> do
            -- mapM_ (mapM_ putStrLn . xxd2 0) (chunksOf 16 d)
            mapM_ putStrLn $ xxd2 0 (L.toStrict d)
            print me
            putStrLn ""
            let Result patched' pe = applyPatch defaultConfig source δ
            mapM_ putStrLn $ xxd2 0 (L.toStrict patched') -- $ L.take 48 patched')
            print pe
            print ("source",source)
            print ("patched",patched)