<commit_before>#
# some tests that actually check their results
#
# $Id$
#

proc search_test {name searchFields expect} {
    puts -nonewline "running $name..."; flush stdout
    set result ""
    set cmd [linsert $searchFields 0 t search -key key -get data -fields "" -code {lappend result $key}]
    #puts $cmd
    eval $cmd

    if {$result != $expect} {
	puts "ERROR IN TEST: $name"
	puts "got '$result'"
	puts "expected '$expect'"
	puts "command '$cmd'"
	puts ""
    } else {
	puts "ok"
    }
}

proc search_test_countonly {name searchFields expect} {
    puts -nonewline "running $name..."; flush stdout
    set cmd [linsert $searchFields 0 t search -countOnly 1]
    #puts $cmd
    set result [eval $cmd]

    if {$result != $expect} {
	puts "ERROR IN TEST: $name"
	puts "got '$result'"
	puts "expected '$expect'"
	puts "command '$cmd'"
	puts ""
    } else {
	puts "ok"
    }

    puts -nonewline "running '$name' without -countOnly..."; flush stdout
    set cmd [linsert $searchFields 0 t search]

    set result [eval $cmd]
        
    if {$result != $expect} {
        puts "ERROR IN TEST: $name"
        puts "got '$result'"
        puts "expected '$expect'"
        puts "command '$cmd'"
        puts ""
    } else {
        puts "ok"
    }
}


proc search_unsorted_test {name searchFields expect} {
    puts -nonewline "running $name..."; flush stdout
    set result ""
    set cmd [linsert $searchFields 0 t search -key key -get data -fields "" -code {lappend result $key}]
    #puts $cmd
    eval $cmd

    if {"[lsort $result]" != "[lsort $expect]"} {
	puts "ERROR IN TEST: $name"
	puts "got '$result'"
	puts "expected '$expect'"
	puts "command '$cmd'"
	puts ""
    } else {
	puts "ok"
    }
}

proc search+_test {name searchFields expect} {
    puts -nonewline "running search+ test $name..."; flush stdout
    set result ""
    set cmd [linsert $searchFields 0 t search+ -get data -fields id -code {lappend result $data}]
    #puts $cmd
    eval $cmd

    if {[lsort $result] != [lsort $expect]} {
	puts "ERROR IN TEST: $name"
	puts "got '$result'"
	puts "expected '$expect'"
	puts "command '$cmd'"
	puts ""
    } else {
	puts "ok"
    }
}


search_unsorted_test "case-insensitive match" {-compare {{match name *VENTURE*}}} {jonas_jr rusty jonas dean hank}

search_unsorted_test "case-sensitive match" {-compare {{match_case name *VENTURE*}}} {}

search_unsorted_test "case-sensitive match 2" {-compare {{match_case name *Tri*}}} {triana}

search_unsorted_test "numeric expression, age < 10" {-compare {{< age 10}}} {carr thundercleese ur inignot frylock shake meatwad}

search_test "sort ascending by age, age < 10" {-sort age -compare {{< age 10}}} {ur inignot carr meatwad frylock shake thundercleese}

search_test "sort descending by age, age < 10" {-sort -age -compare {{< age 10}}} {thundercleese frylock shake meatwad inignot carr ur}

search_test "unanchored match" {-sort name -compare {{match name *Doctor*}}} {doctor_girlfriend jonas jonas_jr orpheus}<commit_msg>Error out of failed tests.<commit_after>#
# some tests that actually check their results
#
# $Id$
#

proc search_test {name searchFields expect} {
    puts -nonewline "running $name..."; flush stdout
    set result ""
    set cmd [linsert $searchFields 0 t search -key key -get data -fields "" -code {lappend result $key}]
    #puts $cmd
    eval $cmd

    if {$result != $expect} {
	puts "ERROR IN TEST: $name"
	puts "got '$result'"
	puts "expected '$expect'"
	puts "command '$cmd'"
	error "ERROR IN TEST: $name"
    } else {
	puts "ok"
    }
}

proc search_test_countonly {name searchFields expect} {
    puts -nonewline "running $name..."; flush stdout
    set cmd [linsert $searchFields 0 t search -countOnly 1]
    #puts $cmd
    set result [eval $cmd]

    if {$result != $expect} {
	puts "ERROR IN TEST: $name"
	puts "got '$result'"
	puts "expected '$expect'"
	puts "command '$cmd'"
	error "ERROR IN TEST: $name"
    } else {
	puts "ok"
    }

    puts -nonewline "running '$name' without -countOnly..."; flush stdout
    set cmd [linsert $searchFields 0 t search]

    set result [eval $cmd]
        
    if {$result != $expect} {
        puts "ERROR IN TEST: $name"
        puts "got '$result'"
        puts "expected '$expect'"
        puts "command '$cmd'"
	error "ERROR IN TEST: $name"
    } else {
        puts "ok"
    }
}


proc search_unsorted_test {name searchFields expect} {
    puts -nonewline "running $name..."; flush stdout
    set result ""
    set cmd [linsert $searchFields 0 t search -key key -get data -fields "" -code {lappend result $key}]
    #puts $cmd
    eval $cmd

    if {"[lsort $result]" != "[lsort $expect]"} {
	puts "ERROR IN TEST: $name"
	puts "got '$result'"
	puts "expected '$expect'"
	puts "command '$cmd'"
	error "ERROR IN TEST: $name"
    } else {
	puts "ok"
    }
}

proc search+_test {name searchFields expect} {
    puts -nonewline "running search+ test $name..."; flush stdout
    set result ""
    set cmd [linsert $searchFields 0 t search+ -get data -fields id -code {lappend result $data}]
    #puts $cmd
    eval $cmd

    if {[lsort $result] != [lsort $expect]} {
	puts "ERROR IN TEST: $name"
	puts "got '$result'"
	puts "expected '$expect'"
	puts "command '$cmd'"
	error "ERROR IN TEST: $name"
    } else {
	puts "ok"
    }
}


search_unsorted_test "case-insensitive match" {-compare {{match name *VENTURE*}}} {jonas_jr rusty jonas dean hank}

search_unsorted_test "case-sensitive match" {-compare {{match_case name *VENTURE*}}} {}

search_unsorted_test "case-sensitive match 2" {-compare {{match_case name *Tri*}}} {triana}

search_unsorted_test "numeric expression, age < 10" {-compare {{< age 10}}} {carr thundercleese ur inignot frylock shake meatwad}

search_test "sort ascending by age, age < 10" {-sort age -compare {{< age 10}}} {ur inignot carr meatwad frylock shake thundercleese}

search_test "sort descending by age, age < 10" {-sort -age -compare {{< age 10}}} {thundercleese frylock shake meatwad inignot carr ur}

search_test "unanchored match" {-sort name -compare {{match name *Doctor*}}} {doctor_girlfriend jonas jonas_jr orpheus}
{'fraction_non_alphanumeric': 0.13728062981794326, 'fraction_numerical': 0.0062325733967525014, 'mean_word_length': 3.282303370786517, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7373950', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2057, 'n_words': 737}