You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
555 lines
12 KiB
555 lines
12 KiB
(ns rustint.core-test
|
|
(:require [clojure.test :refer :all]
|
|
[rustint.core :refer :all]))
|
|
|
|
(deftest pasar-a-float-test01
|
|
(testing "Test 01 pasar-a-float"
|
|
(is (= (pasar-a-float 10) 10.0))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-float-test02
|
|
(testing "Test 02 pasar-a-float"
|
|
(is (= (pasar-a-float "10") 10.0))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-float-test03
|
|
(testing "Test 03 pasar-a-float"
|
|
(is (= (pasar-a-float 10.0) 10.0))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-float-test04
|
|
(testing "Test 04 pasar-a-float"
|
|
(is (= (pasar-a-float 'a) 'a))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-float-test05
|
|
(testing "Test 05 pasar-a-float"
|
|
(is (= (pasar-a-float [10]) [10]))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-int-test01
|
|
(testing "Test 01 int pasar-a-int"
|
|
(is (= (pasar-a-int "10") 10))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-int-test02
|
|
(testing "Test 02 int pasar-a-int"
|
|
(is (= (pasar-a-int 10.0) 10))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-int-test03
|
|
(testing "Test 03 int pasar-a-int"
|
|
(is (= (pasar-a-int 10) 10))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-int-test04
|
|
(testing "Test 04 int pasar-a-int"
|
|
(is (= (pasar-a-int 'a) 'a))
|
|
)
|
|
)
|
|
|
|
(deftest pasar-a-int-test05
|
|
(testing "Test 05 int pasar-a-int"
|
|
(is (= (pasar-a-int [10]) [10]))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test01
|
|
(testing "Test 01 compatibles?"
|
|
(is (= (compatibles? 'i64 5) true))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test02
|
|
(testing "Test 02 compatibles?"
|
|
(is (= (compatibles? 'i64 5.0) false))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test03
|
|
(testing "Test 03 compatibles?"
|
|
(is (= (compatibles? 'i64 [5.0]) true))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test04
|
|
(testing "Test 04 compatibles?"
|
|
(is (= (compatibles? 'f64 5.0) true))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test05
|
|
(testing "Test 05 compatibles?"
|
|
(is (= (compatibles? 'String "Hola") true))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test06
|
|
(testing "Test 06 compatibles?"
|
|
(is (= (compatibles? 'bool true) true))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test07
|
|
(testing "Test 07 compatibles?"
|
|
(is (= (compatibles? 'bool 1) false))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test08
|
|
(testing "Test 08 compatibles?"
|
|
(is (= (compatibles? 'usize 1) true))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test09
|
|
(testing "Test 09 compatibles?"
|
|
(is (= (compatibles? 'char \a) true))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test10
|
|
(testing "Test 10 compatibles?"
|
|
(is (= (compatibles? 'char 'a) false))
|
|
)
|
|
)
|
|
|
|
(deftest compatibles-test11
|
|
(testing "Test 11 compatibles?"
|
|
(is (= (compatibles? 'char ['a]) true))
|
|
)
|
|
)
|
|
|
|
(deftest dividir-test01
|
|
(testing "Test 01 dividir"
|
|
(is (= (dividir 12 3) 4))
|
|
)
|
|
)
|
|
|
|
(deftest dividir-test02
|
|
(testing "Test 02 dividir"
|
|
(is (= (dividir 12.0 3) 4.0))
|
|
)
|
|
)
|
|
|
|
(deftest dividir-test03
|
|
(testing "Test 03 dividir"
|
|
(is (= (dividir 12 3.0) 4.0))
|
|
)
|
|
)
|
|
|
|
(deftest dividir-test04
|
|
(testing "Test 04h dividir"
|
|
(is (= (dividir 12.0 3.0) 4.0))
|
|
)
|
|
)
|
|
|
|
(deftest dividir-test05
|
|
(testing "Test 05 dividir"
|
|
(is (= (dividir 1 2) 0))
|
|
)
|
|
)
|
|
|
|
(deftest dividir-test06
|
|
(testing "Test 06 dividir"
|
|
(is (= (dividir 1 2.0) 0.5))
|
|
)
|
|
)
|
|
|
|
(deftest identificador-test01
|
|
(testing "Test 01 identificador"
|
|
(is (= (identificador? 'boolean) true))
|
|
)
|
|
)
|
|
|
|
(deftest identificador-test02
|
|
(testing "Test 02 identificador"
|
|
(is (= (identificador? 'bool) false))
|
|
)
|
|
)
|
|
|
|
(deftest identificador-test03
|
|
(testing "Test 03 identificador"
|
|
(is (= (identificador? 'e120) true))
|
|
)
|
|
)
|
|
|
|
(deftest identificador-test04
|
|
(testing "Test 04 identificador"
|
|
(is (= (identificador? '12e0) false))
|
|
)
|
|
)
|
|
|
|
(deftest palabra-reservada-test01
|
|
(testing "Test 01 palabra reservada"
|
|
(is (= (palabra-reservada? 'while) true))
|
|
)
|
|
)
|
|
|
|
(deftest palabra-reservada-test02
|
|
(testing "Test 02 palabra reservada"
|
|
(is (= (palabra-reservada? 'until) false))
|
|
)
|
|
)
|
|
|
|
(deftest palabra-reservada-test03
|
|
(testing "Test 03 palabra reservada"
|
|
(is (= (palabra-reservada? 13) false))
|
|
)
|
|
)
|
|
|
|
(deftest dump-01
|
|
(testing "Test 01 dump"
|
|
(let [
|
|
printed (with-out-str (dump '[[POPREF 2] [PUSHFI 2] MUL [PUSHFI 1] ADD NEG]))
|
|
]
|
|
(is (= printed "0 [POPREF 2]\n1 [PUSHFI 2]\n2 MUL\n3 [PUSHFI 1]\n4 ADD\n5 NEG\n"
|
|
))
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest dump-01-nil
|
|
(testing "Test 01 dump nil"
|
|
(is (nil? (dump '[[POPREF 2] [PUSHFI 2] MUL [PUSHFI 1] ADD NEG])))
|
|
)
|
|
)
|
|
|
|
(deftest dump-02
|
|
(testing "Test 02 dump"
|
|
(let [
|
|
printed (with-out-str (dump '[HLT]))
|
|
]
|
|
(is (= printed "0 HLT\n"
|
|
))
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest dump-02-nil
|
|
(testing "Test 02 dump nil"
|
|
(is (nil? (dump '[HLT])))
|
|
)
|
|
)
|
|
|
|
(deftest dump-03
|
|
(testing "Test 03 dump"
|
|
(let [
|
|
printed (with-out-str (dump nil))
|
|
]
|
|
(is (= printed "0 nil\n"
|
|
))
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest dump-03-nil
|
|
(testing "Test 03 dump nil"
|
|
(is (nil? (dump nil)))
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-01
|
|
(testing "Test 01 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("Hola, mundo!"))
|
|
'("Hola, mundo!")
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-02
|
|
(testing "Test 02 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("Hola, mundo 2!"))
|
|
'("Hola, mundo 2!")
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-03
|
|
(testing "Test 03 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("Hola, mundo {}!" 2))
|
|
'("Hola, mundo %d!" 2)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-04
|
|
(testing "Test 04 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("Hola, mundo {}!" 2.0))
|
|
'("Hola, mundo %.0f!" 2.0)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-05
|
|
(testing "Test 05 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("Hola, mundo {}!" "2"))
|
|
'("Hola, mundo %s!" "2")
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-06
|
|
(testing "Test 06 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("Hola, mundo {} {} {}!" 2 2.0 "2"))
|
|
'("Hola, mundo %d %.0f %s!" 2 2.0 "2")
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-07
|
|
(testing "Test 07 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("Hola, mundo {:.8}!" 2.0))
|
|
'("Hola, mundo %.8f!" 2.0)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-08
|
|
(testing "Test 08 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("- My name is {}, James {}.\n- Hello, {}{}{}!" "Bond" "Bond" 0 0 7))
|
|
'("- My name is %s, James %s.\n- Hello, %d%d%d!" "Bond" "Bond" 0 0 7)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-09
|
|
(testing "Test 09 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("{} elevado a la {} es\t{}" 2.0 2 4.0))
|
|
'("%.0f elevado a la %d es\t%.0f" 2.0 2 4.0)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest convertir-formato-impresion-10
|
|
(testing "Test 10 convertir-formato-impresion"
|
|
(is (=
|
|
(convertir-formato-impresion '("Las raices cuadradas de {} son +{:.8} y -{:.8}" 4.0 1.999999999985448 1.999999999985448))
|
|
'("Las raices cuadradas de %.0f son +%.8f y -%.8f" 4.0 1.999999999985448 1.999999999985448)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest get-rust-formatters-01
|
|
(testing "Test 01 get-rust-formatters"
|
|
(is (=
|
|
(get-rust-formatters "Hola, Mundo!")
|
|
'()
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest get-rust-formatters-02
|
|
(testing "Test 02 get-rust-formatters"
|
|
(is (=
|
|
(get-rust-formatters "- My name is {}, James {}.\n- Hello, {}{}{}!")
|
|
'(nil nil nil nil nil)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest get-rust-formatters-03
|
|
(testing "Test 03 get-rust-formatters"
|
|
(is (=
|
|
(get-rust-formatters "{} elevado a la {} es\t{}")
|
|
'(nil nil nil)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest get-rust-formatters-04
|
|
(testing "Test 04 get-rust-formatters"
|
|
(is (=
|
|
(get-rust-formatters "Las raices cuadradas de {} son +{:.8} y -{:.8}")
|
|
'(nil ".8" ".8")
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest test-especificador-formato-01
|
|
(testing "Test 01 especificador formato"
|
|
(is (=
|
|
(especificador-formato "Bond" nil)
|
|
"%s"
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest test-especificador-formato-02
|
|
(testing "Test 02 especificador formato"
|
|
(is (=
|
|
(especificador-formato 0 nil)
|
|
"%d"
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest test-especificador-formato-03
|
|
(testing "Test 03 especificador formato"
|
|
(is (=
|
|
(especificador-formato 2.0 nil)
|
|
"%.0f"
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest test-especificador-formato-04
|
|
(testing "Test 04 especificador formato"
|
|
(is (=
|
|
(especificador-formato 2.0 ".4")
|
|
"%.4f"
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest test-especificador-formato-05
|
|
(testing "Test 05 especificador formato"
|
|
(is (=
|
|
(especificador-formato 2.0 ".8")
|
|
"%.8f"
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest test-listar-01
|
|
(testing "Test 01 listar"
|
|
(let [
|
|
printed (with-out-str (listar (list 'fn 'main (symbol "(") (symbol ")") (symbol "{") 'println! (symbol "(") "Hola, mundo!" (symbol ")") (symbol "}"))))
|
|
]
|
|
(is (=
|
|
printed
|
|
"fn main ( )\n{\n println! ( \"Hola, mundo!\" )\n}"
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(deftest test-ya-declarado-localmente-01
|
|
(testing "Test 01 ya-declarado-localmente?"
|
|
(is (= (ya-declarado-localmente?
|
|
'Write
|
|
[
|
|
[0]
|
|
[
|
|
['io ['lib '()] 0]
|
|
['Write ['lib '()] 0]
|
|
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
|
|
]
|
|
]
|
|
) true))
|
|
)
|
|
)
|
|
|
|
(deftest test-ya-declarado-localmente-02
|
|
(testing "Test 02 ya-declarado-localmente?"
|
|
(is (= (ya-declarado-localmente?
|
|
'Read
|
|
[
|
|
[0]
|
|
[
|
|
['io ['lib '()] 0]
|
|
['Write ['lib '()] 0]
|
|
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
|
|
]
|
|
]
|
|
)
|
|
false))
|
|
)
|
|
)
|
|
|
|
(deftest test-ya-declarado-localmente-03
|
|
(testing "Test 03 ya-declarado-localmente?"
|
|
(is (= (ya-declarado-localmente?
|
|
'Write
|
|
[
|
|
[0 1]
|
|
[
|
|
['io ['lib '()] 0]
|
|
['Write ['lib '()] 0]
|
|
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
|
|
]
|
|
]
|
|
)
|
|
true))
|
|
)
|
|
)
|
|
|
|
(deftest test-ya-declarado-localmente-04
|
|
(testing "Test 04 ya-declarado-localmente?"
|
|
(is (= (ya-declarado-localmente?
|
|
'Write
|
|
[
|
|
[0 2]
|
|
[
|
|
['io ['lib '()] 0]
|
|
['Write ['lib '()] 0]
|
|
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
|
|
]
|
|
]
|
|
)
|
|
false))
|
|
)
|
|
)
|
|
|
|
(deftest test-buscar-tipo-de-retorno-01
|
|
(testing "Test 01 buscar-tipo-de-retorno"
|
|
(is (=
|
|
(buscar-tipo-de-retorno [
|
|
(symbol ";")
|
|
(list 'println! (symbol "(") "La suma de 5 mas 7 es {}" (symbol ",") 'suma (symbol "(") 5 (symbol ",") 7 (symbol ")") (symbol ")") (symbol ";") (symbol "}"))
|
|
['fn 'suma (symbol "(") 'x (symbol ":") 'i64 (symbol ",") 'y (symbol ":") 'i64 (symbol ")") (symbol "->") 'i64 (symbol "{") 'x '+ 'y (symbol "}") 'fn 'main (symbol "(") (symbol ")") (symbol "{") 'suma (symbol "(") 5 (symbol ",") 7 (symbol ")")]
|
|
:sin-errores
|
|
[
|
|
[0 2]
|
|
[
|
|
['suma ['fn [(list ['x (symbol ":") 'i64] ['y (symbol ":") 'i64]) 'i64]] 2]
|
|
['main ['fn [() ()]] 8]
|
|
]
|
|
]
|
|
0
|
|
[['CAL 8] 'HLT ['POPARG 1] ['POPARG 0] ['PUSHFM 0] ['PUSHFM 1] 'ADD 'RET ['PUSHFI 5] ['PUSHFI 7] ['CAL 2]]
|
|
[[2 ['i64 nil] ['i64 nil]] [8]]
|
|
]
|
|
2)
|
|
'i64
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|