REBOL [
	Title:   "Generates Red equal? tests"
	Author:  "Peter W A Wood"
	File: 	 %make-equal-auto-test.r
	Version: 0.1.0
	Tabs:	 4
	Rights:  "Copyright (C) 2011-2015 Peter W A Wood. All rights reserved."
	License: "BSD-3 - https://github.com/red/red/blob/origin/BSD-3-License.txt"
]

;; initialisations 

make-dir %auto-tests/
infix-file: %auto-tests/infix-equal-auto-test.red
prefix-file: %auto-tests/equal-auto-test.red

test-src: {
Red [
	Title:   "Red infix or prefix equal test script"
	Author:  "Nenad Rakocevic & Peter W A Wood"
	File: 	 ***FILE***
	Tabs:	 4
	Rights:  "Copyright (C) 2011-2015, Nenad Rakocevic & Peter W A Wood. All rights reserved."
	License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt"
]

comment {  This file is generated by make-equal-auto-test.r
  Do not edit this file directly.
}

;make-length:***MAKELENGTH***           

#include  %../../../../quick-test/quick-test.red
}

;;functions

group-title: ""                         ;; title of current group
group-test-no: 0                        ;; number of current test in group

add-equal-test: func [
  expected [string!]
  actual   [string!]
][
  add-test
  append infix-src join {--assert } [expected " = " actual newline]
  append prefix-src join {--assert equal? } [expected " " actual newline]
]

add-not-equal-test: func [
  expected [string!]
  actual   [string!]
][
  add-test
  append infix-src join {--assert not } [expected " = " actual newline]
  append prefix-src join {--assert not equal? } [expected " " actual newline]
]

add-test: func [] [
  group-test-no: group-test-no + 1
  append infix-src join {--test-- "infix-equal-} 
    [group-title "-" group-test-no {"} newline]
  append prefix-src join {--test-- "prefix-equal-} 
    [group-title "-" group-test-no {"} newline]
]

add-test-with-code: func [
  code        [string!]
  assertion   [string!]
][
  add-test
  append infix-src join code newline
  append prefix-src join code newline
  append infix-src join {--assert } [assertion newline]
  append prefix-src join {--assert } [assertion newline]
]
  
add-test-text: func [
  text  [string!]
][
  append infix-src join replace copy text "***FIX***" "infix" newline
  append prefix-src join replace copy text "***FIX***" "prefix" newline
]


start-group: func [
  title [string!]
][
  group-title: title
  group-test-no: 0
  add-test-text join {===start-group=== "} [title {"}]
]
  

;; processing 
replace test-src {***MAKELENGTH***} length? read %make-equal-auto-test.r
infix-src: copy test-src
replace infix-src {***FILE***} :infix-file
prefix-src: copy test-src
replace prefix-src {***FILE***} :prefix-file

add-test-text {~~~start-file~~~ "***FIX***-equal"}

start-group "same-datatype"
add-equal-test "0" "0"
add-equal-test "1" "1"
add-equal-test "FFFFFFFFh" "-1"
add-equal-test "[]" "[]"
add-equal-test "[a]" "[a]"
add-equal-test "[A]" "[a]"
add-equal-test "['a]" "[a]"
add-equal-test "[a:]" "[a]"
add-equal-test "[:a]" "[a]"
add-equal-test "[:a]" "[a:]"
add-equal-test "[abcde]" "[abcde]"
add-equal-test "[a b c d]" "[a b c d]"
add-equal-test "[b c d]" "next [a b c d]"
add-equal-test "[b c d]" "(next [a b c d])"
add-equal-test {"a"} {"a"}
add-equal-test {"a"} {"A"}
add-equal-test {"abcdeè"} {"abcdeè"}
add-equal-test {(next "abcdeè")} {next "abcdeè"}
add-equal-test {(first "abcdeè")} {first "abcdeè"}
add-equal-test {(last "abcdeè")} {last "abcdeè"}
add-equal-test {"abcde^^(2710)é^^(010000)"} {"abcde^^(2710)é^^(010000)"} 
;; need to escape the ^ as file is processed by REBOL
add-equal-test {[d]} {back tail [a b c d]}
add-equal-test {"2345"} {next "12345"}
add-equal-test {#"z"} {#"z"}
add-not-equal-test {#"z"} {#"Z"}
add-not-equal-test {#"e"} {#"è"}
add-equal-test {#"^^(010000)"} {#"^^(010000)"}
add-equal-test {true} {true}
add-equal-test {false} {false}
add-not-equal-test {false} {true}
add-not-equal-test {true} {false}
add-equal-test {none} {none}
add-equal-test {'a} {'a}
add-equal-test {'a} {'A}
add-equal-test {(first [a])} {first [a]}
add-equal-test {'a} {first [A]}
add-equal-test {'a} {first ['a]}
add-equal-test {'a} {first [:a]}
add-equal-test {'a} {first [a:]}
add-equal-test {(first [a:])} {first [a:]}
add-equal-test {(first [:a])} {first [:a]}
add-equal-test {[a b c d e]} {first [[a b c d e]]}
add-test-with-code {ea-result: 1 = 1} {ea-result = true}
add-test-with-code {ea-result: 1 = 0} {ea-result = false}
add-test-with-code {ea-result: equal? 1 1} {ea-result = true}
add-test-with-code {ea-result: equal? 1 0} {ea-result = false}
add-test-text {===end-group===}

start-group {implcit-cast}
add-equal-test {#"0"} {48}
add-equal-test {48} {#"0"}
add-equal-test {#"^^(2710)"} {10000}
add-equal-test {#"^^(010000)"} {65536}
add-test-with-code {ea-result: #"1" = 49} {ea-result = true}
add-test-with-code {ea-result: equal? #"^^(010000)" 10000} {ea-result = false}
add-test-text {===end-group===}

add-test-text {~~~end-file~~~}

write infix-file infix-src
write prefix-file prefix-src

print "Equal auto test files generated"

