<commit_before>(ns structural-typing.docs.f-wiki-what-can-be-in-a-path
 (:require [structural-typing.type :refer :all]
           [structural-typing.global-type :refer :all]
           [clojure.string :as str])
 (:use midje.sweet))

(start-over!)

(fact "keywords"
  (type! :X {[:a :b] integer?})
  (described-by? :X {:a {:b 1}}) => true)

(fact "ALL"
  (type! :IntArray {[ALL] integer?})
  (described-by? :IntArray [1 2 3 4]) => true
  (let [result (with-out-str (checked :IntArray [1 :a 2 :b]))]
    result => #"\[1\] should be `integer"
    result => #"\[3\] should be `integer")

  (type! :D2 {[ALL ALL] integer?})
  (let [result (with-out-str (checked :D2 [  [0 :elt-0-1] [:elt-1-0] [] [0 0 :elt-3-2]]))]
    result => #"\[0 1\] should be `integer\?`; it is `:elt-0-1`"
    result => #"\[1 0\] should be `integer\?`; it is `:elt-1-0`"
    result => #"\[3 2\] should be `integer\?`; it is `:elt-3-2`")

  (type! :Nesty {[:x ALL ALL :y] integer?})
  (let [result (with-out-str (checked :Nesty {:x [ [{:y 1}] [{:y :notint}]]}))]
    result => #"\[:x 1 0 :y\] should be `integer\?`; it is `:notint`")

  (let [result (with-out-str (checked :Nesty {:x [1]}))]
    result => #"\[:x ALL ALL :y\] is not a path"))

(fact "predicates"
  (type! :Odder {[ALL even?] neg?, [ALL odd?] pos?})
  (let [result (with-out-str (checked :Odder [4 -3 2 -1]))]
    result => #"\[0 even\?\] should be `neg\?`; it is `4`"
    result => #"\[2 even\?\] should be `neg\?`; it is `2`"
    result => #"\[1 odd\?\] should be `pos\?`; it is `-3`"
    result => #"\[3 odd\?\] should be `pos\?`; it is `-1`"))

(start-over!)<commit_msg>Add wiki page examples<commit_after>(ns structural-typing.docs.f-wiki-what-can-be-in-a-path
 (:require [structural-typing.type :refer :all]
           [structural-typing.global-type :refer :all]
           [clojure.string :as str])
 (:use midje.sweet))

(start-over!)

(fact "keywords"
  (type! :X {[:a :b] integer?})
  (described-by? :X {:a {:b 1}}) => true)

(fact "ALL"
  (type! :IntArray {[ALL] integer?})
  (described-by? :IntArray [1 2 3 4]) => true
  (let [result (with-out-str (checked :IntArray [1 :a 2 :b]))]
    result => #"\[1\] should be `integer"
    result => #"\[3\] should be `integer")

  (type! :D2 {[ALL ALL] integer?})
  (let [result (with-out-str (checked :D2 [  [0 :elt-0-1] [:elt-1-0] [] [0 0 :elt-3-2]]))]
    result => #"\[0 1\] should be `integer\?`; it is `:elt-0-1`"
    result => #"\[1 0\] should be `integer\?`; it is `:elt-1-0`"
    result => #"\[3 2\] should be `integer\?`; it is `:elt-3-2`")

  (type! :Nesty {[:x ALL ALL :y] integer?})
  (let [result (with-out-str (checked :Nesty {:x [ [{:y 1}] [{:y :notint}]]}))]
    result => #"\[:x 1 0 :y\] should be `integer\?`; it is `:notint`")

  (let [result (with-out-str (checked :Nesty {:x [1]}))]
    result => #"\[:x ALL ALL :y\] is not a path"))

(fact "RANGE"
  (type! :ALL {[ALL] even?})
  (let [result (with-out-str (checked :ALL [:wrong 4 2 :wrong]))]
    result => #"\[0\] should be `even\?`; it is `:wrong`"
    result => #"\[3\] should be `even\?`; it is `:wrong`")

  (type! :R {[(RANGE 1 3)] even?})
  (checked :R [:wrong 4 2 :wrong]) => [:wrong 4 2 :wrong]

  (type! :R {[ALL :x (RANGE 1 3)] even?})
  (let [result (with-out-str (checked :R [ {:x [:ignored 4 2]} 
                                           {:x [:ignored 1 2 :ignored]}]))]
    result => #"\[1 :x 1\] should be `even\?`; it is `1`")

  (type! :SECOND-AND-THIRD {[(RANGE 1 3)] pos?})
  (checked :SECOND-AND-THIRD [:ignored 1 2]) => [:ignored 1 2]
  (let [result (with-out-str (checked :SECOND-AND-THIRD [:ignored 1]))]
    result => #"\[\(RANGE 1 3\)\] is not a path into `\[:ignored 1\]`"))
  
  

(fact "predicates"
  (type! :Odder {[ALL even?] neg?, [ALL odd?] pos?})
  (let [result (with-out-str (checked :Odder [4 -3 2 -1]))]
    result => #"\[0 even\?\] should be `neg\?`; it is `4`"
    result => #"\[2 even\?\] should be `neg\?`; it is `2`"
    result => #"\[1 odd\?\] should be `pos\?`; it is `-3`"
    result => #"\[3 odd\?\] should be `pos\?`; it is `-1`"))

(start-over!)
{'fraction_non_alphanumeric': 0.25740375123395853, 'fraction_numerical': 0.030848963474827247, 'mean_word_length': 2.908389585342334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1216476', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1667, 'n_words': 519}