/**
 * Test module for string-misc
 */
module string-misc-test
imports libstratego-lib
strategies

  main =
    test-suite(!"String Misc test suite",
      test-all-lines
    ; test-string-tokenize
    ; test-indent-text
    ; test-trim-trailing
    ; test-get-all-lines
    ; test-starts-with
    ; test-ends-with

    ; test-shuffle-1
    ; test-shuffle-word-mids-1
    ; test-shuffle-word-mids-2
    )
    
  test-all-lines =
     apply-test(!"test-all-lines-1"
        , all-lines(<conc-strings> (<id>, "EOL"))
        , !"the first line\nSecond line, third will be empty\n\nThis is the fourth, a final empty should not follow\n"
        , !"the first lineEOL\nSecond line, third will be emptyEOL\nEOL\nThis is the fourth, a final empty should not followEOL\n")
   ; apply-test(!"test-all-lines-2"
        , all-lines(<conc-strings> (<id>, "EOL"))
        , !"\nAfter first empty line: Second line, third will be empty\n\nThis is the fourth, a final empty should not follow"
        , !"EOL\nAfter first empty line: Second line, third will be emptyEOL\nEOL\nThis is the fourth, a final empty should not followEOL")

  test-string-tokenize =
     apply-test(!"test-string-tokenize-keep-empty-1"
        , string-tokenize-keep-empty(|['\n'])
        , !"the first line\nSecond line, third will be empty\n\nThis is the fourth, a final empty will follow\n"
        , !["the first line", "Second line, third will be empty", "", "This is the fourth, a final empty will follow", ""])
   ; apply-test(!"test-string-tokenize-keep-empty-2"
        , string-tokenize-keep-empty(|['\n'])
        , !""
        , ![""])
   ; apply-test(!"test-string-tokenize-keep-empty-3"
        , string-tokenize-keep-empty(|['\n'])
        , !"\n\n"
        , !["","",""])
   ; apply-test(!"test-string-tokenize-keep-all-1"
        , string-tokenize-keep-all(|['\n'])
        , !"the first line\nSecond line, third will be empty and tokenized\n\nThis is the fourth, a final empty will follow\n"
        , !["the first line", "\n","Second line, third will be empty and tokenized", "\n", "", "\n", "This is the fourth, a final empty will follow", "\n", ""])
   ; apply-test(!"test-string-tokenize-keep-all-2"
        , string-tokenize-keep-all(|['\n'])
        , !""
        , ![""])
   ; apply-test(!"test-string-tokenize-keep-all-3"
        , string-tokenize-keep-all(|['\n'])
        , !"\n\n"
        , !["","\n","","\n",""])

  test-indent-text =
     apply-test(!"test-indent-text-1"
        , indent-text(|4)
        , !"the first line\nSecond line, third will be empty\n\nThis is the fourth, a final empty should not follow\n"
        , !"    the first line\n    Second line, third will be empty\n    \n    This is the fourth, a final empty should not follow\n")

  test-trim-trailing =
     apply-test(!"test-trim-trailing-1"
        , all-lines(trim-trailing-whitespace)
        , !"the first line    \nSecond line, third will be empty\n \nThis is the fourth, a final empty should not follow\n   "
        , !"the first line\nSecond line, third will be empty\n\nThis is the fourth, a final empty should not follow\n")

  test-get-all-lines = id
    ; apply-test(!"test-get-all-lines-1"
      , get-lines
      , !"the first line\nSecond line, third will be empty\n\nThis is the fourth, a final empty will follow\n"
      , !["the first line","Second line, third will be empty","","This is the fourth, a final empty will follow",""]
      )
    ; apply-test(!"test-get-all-lines-2"
      , get-lines
      , !"1\n2"
      , !["1", "2"]
      )
    ; apply-test(!"test-get-all-lines-3"
      , get-lines
      , !"1\r\n2"
      , !["1", "2"]
      )
    ; apply-test(!"test-get-all-lines-4"
      , get-lines
      , !"1\r2"
      , !["1", "2"]
      )
    ; apply-test(!"test-get-all-lines-5"
      , get-lines
      , !"1\n\n2"
      , !["1", "", "2"]
      )
    ; apply-test(!"test-get-all-lines-6"
      , get-lines
      , !"1\r\n\r\n2"
      , !["1", "", "2"]
      )
    ; apply-test(!"test-get-all-lines-7"
      , get-lines
      , !"1\r\r2"
      , !["1", "", "2"]
      )
    ; apply-test(!"test-get-all-lines-8"
      , get-lines
      , !"1\n2\n3"
      , !["1", "2", "3"]
      )
    ; apply-test(!"test-get-all-lines-9"
      , get-lines
      , !"1\r\n2\r\n3"
      , !["1", "2", "3"]
      )
    ; apply-test(!"test-get-all-lines-10"
      , get-lines
      , !"1\r2\r3"
      , !["1", "2", "3"]
      )
    ; apply-test(!"test-get-all-lines-11"
      , get-lines
      , !"1"
      , !["1"]
      )
    ; apply-test(!"test-get-all-lines-12"
      , get-lines
      , !""
      , ![""]
      )

  test-starts-with = 
     apply-test(!"test-string-starts-with-1"
       , string-starts-with(|"foo")
       , !"foobar"
       , !"foobar")
   ; apply-and-fail(!"test-string-starts-with-2"
       , string-starts-with(|"foo")
       , !"frobbar")

  test-ends-with = 
     apply-test(!"test-string-ends-with-1"
       , string-ends-with(|"bar")
       , !"foobar"
       , !"foobar")
   ; apply-and-fail(!"test-string-ends-with-2"
       , string-ends-with(|"bar")
       , !"foobaz")
       
  test-shuffle-1 =
     testing(!"test-shuffle-1"
        , <shuffle> [1, 2, 3, 4, 5, 6, 7, 8, 9])

  test-shuffle-word-mids-1 =
     testing(!"test-shuffle-word-mids-1"
        , <shuffle-word-mids> "Goedemorgen")

  test-shuffle-word-mids-2 =
     testing(!"test-shuffle-word-mids-2"
        , <shuffle-word-mids> "Stratego/XT is a framework for the development of transformation systems aiming to support a wide range of program transformations. The framework consists of the transformation language Stratego and the XT collection of transformation tools.")
        
        
