File: Main.hs

package info (click to toggle)
haskell-neat-interpolation 0.5.1.4-2
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 76 kB
  • sloc: haskell: 255; makefile: 5
file content (64 lines) | stat: -rw-r--r-- 2,062 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module Main where

import NeatInterpolation
import Test.Tasty
import Test.Tasty.HUnit
import Prelude hiding (choose)

main :: IO ()
main =
  defaultMain $
    testGroup "" $
      [ testCase "Demo" $
          let template a b =
                [trimming|
          function(){
            function(){
              $a
            }
            return $b
          }
        |]
              a = "{\n  indented line\n  indented line\n}"
           in assertEqual
                ""
                "function(){\n  function(){\n    {\n      indented line\n      indented line\n    }\n  }\n  return {\n    indented line\n    indented line\n  }\n}"
                (template a a),
        testCase "Isolation" $
          let isolated name = [trimming|this_could_be_${name}_long_identifier|]
           in assertEqual
                ""
                "this_could_be_one_long_identifier"
                (isolated "one"),
        testCase "Escaping 1" $
          let template a b =
                [trimming|
          function(){
            function(){
              $a
            }
            return "$$b"
          }
        |]
              a = "{\n  indented line\n  indented line\n}"
           in assertEqual
                ""
                "function(){\n  function(){\n    {\n      indented line\n      indented line\n    }\n  }\n  return \"$b\"\n}"
                (template a a),
        testCase "Escaping 2" $
          let escaped name = [trimming|this_could_be_$$${name}$$_long_identifier|]
           in assertEqual
                ""
                "this_could_be_$one$_long_identifier"
                (escaped "one"),
        testCase "Deindentation" $
          let template fieldName className =
                [trimming|
          * @param $fieldName value of the {@code $fieldName} property of
                   the {@code $className} case
        |]
           in assertEqual
                ""
                "* @param a value of the {@code a} property of\n         the {@code b} case"
                (template "a" "b")
      ]