REBOL [
	Title:   "Generates Red greater? and greater-or-equal? tests"
	Author:  "Peter W A Wood"
	File: 	 %make-greater-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-greater-auto-test.red
prefix-file: %auto-tests/greater-auto-test.red
infix-file2: %auto-tests/infix-greater-equal-auto-test.red
prefix-file2: %auto-tests/greater-equal-auto-test.red

test-src: {
Red [
	Title:   "Red infix or prefix greater? or greater-or-equal? test script"
	Author:  "Nenad Rakocevic & Peter W A Wood"
	File: 	 ***FILE***
	Tabs:	 4
	Rights:  "Copyright (C) 2011-2013, 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-greater-test: func [
  expected 				[string!]
  actual   				[string!]
  greater-true			[logic!]
  greater-equal-true	[logic!]
][
	add-test
	append infix-src join {--assert } 
		compose [(either greater-true [""] ["not "]) expected  " > " actual newline]
  	append prefix-src join {--assert }
  		compose [(either greater-true [""] ["not"]) " greater? " expected " " actual newline]
  	append infix-src2 join {--assert } 
  		compose [(either greater-equal-true [""] ["not "]) expected  " >= " actual newline]
  	append prefix-src2 join {--assert }
  		compose [(either greater-equal-true [""]["not"]) " greater-or-equal? " expected " " actual newline]
]

add-test: func [] [
  group-test-no: group-test-no + 1
  append infix-src join {--test-- "infix-greater-} 
    [group-title "-" group-test-no {"} newline]
  append prefix-src join {--test-- "prefix-greater-} 
    [group-title "-" group-test-no {"} newline]
  append infix-src2 join {--test-- "infix-greater-equal-} 
    [group-title "-" group-test-no {"} newline]
  append prefix-src2 join {--test-- "prefix-greater-equal-} 
    [group-title "-" group-test-no {"} 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
  append infix-src2 join replace copy text "***FIX***" "infix" newline
  append prefix-src2 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-greater-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
infix-src2: copy test-src
replace infix-src2 {***FILE***} :infix-file2
prefix-src2: copy test-src
replace prefix-src2 {***FILE***} :prefix-file2

append infix-src  {~~~start-file~~~ "infix-greater?"}
append prefix-src  {~~~start-file~~~ "prefix-greater?"}
append infix-src2  {~~~start-file~~~ "infix-greater-or-equal?"}
append prefix-src2  {~~~start-file~~~ "prefix-greater-or-equal?"}

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

start-group {implcit-cast}
add-greater-test {#"0"} {48} false true
add-greater-test {48} {#"0"} false true
add-greater-test {#"^^(2710)"} {10000} false true
add-greater-test {#"^^(010000)"} {65536} false true
add-test-text {===end-group===}

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

write infix-file infix-src
write prefix-file prefix-src
write infix-file2 infix-src2
write prefix-file2 prefix-src2

print "Lesser auto test files generated"
