Skip to content

Commit 7d1976e

Browse files
committed
More tests
1 parent cd3adc3 commit 7d1976e

File tree

10 files changed

+630
-87
lines changed

10 files changed

+630
-87
lines changed

src/stan_math_backend/Cpp_Json.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ let%expect_test "outvar to json pretty" =
6565
unslash the ones near a plus*)
6666
let replace_cpp_expr s =
6767
s
68-
|> String.substr_replace_all ~pattern:{|"|} ~with_:{|\"|}
68+
|> String.substr_replace_all ~pattern:"\\n" ~with_:""
69+
|> Cpp_str.escaped
6970
|> String.substr_replace_all ~pattern:{|\"+|} ~with_:{|" +|}
7071
|> String.substr_replace_all ~pattern:{|+\"|} ~with_:{|+ "|}
71-
|> String.substr_replace_all ~pattern:"\\n" ~with_:""
7272

7373
let wrap_in_quotes s = "\"" ^ s ^ "\""
7474

@@ -79,9 +79,12 @@ let out_var_interpolated_json_str vars =
7979
let%expect_test "outvar to json" =
8080
let var x = {Expr.Fixed.pattern= Var x; meta= Expr.Typed.Meta.empty} in
8181
[ ( "var_one"
82-
, SizedType.SArray (SVector (AoS, var "N"), var "K")
82+
, SizedType.SArray
83+
( SVector
84+
(AoS, Expr.Helpers.binop (var "N") Operator.Minus Expr.Helpers.one)
85+
, var "K" )
8386
, Program.Parameters ) ]
8487
|> out_var_interpolated_json_str |> print_endline;
8588
[%expect
8689
{|
87-
"[{\"name\":\"var_one\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(K) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "}},\"block\":\"parameters\"}]" |}]
90+
"[{\"name\":\"var_one\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(K) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string((N -1)) + "}},\"block\":\"parameters\"}]" |}]

test/integration/bad/stanc.expected

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,6 +2969,19 @@ Semantic error in 'typo.stan', line 2, column 17 to column 34:
29692969

29702970
A returning function was expected but an undeclared identifier 'to_vetor' was supplied.
29712971
A similar known identifier is 'to_vector'
2972+
[exit 1]
2973+
$ ../../../../install/default/bin/stanc unicode-without-flag.stan
2974+
Syntax error in 'unicode-without-flag.stan', line 4, column 24, lexing error:
2975+
-------------------------------------------------
2976+
2: int<lower=0> J; // number of schools
2977+
3: array[J] real y; // estimated treatment effect (school j)
2978+
4: array[J] real<lower=0> σ; // std err of effect estimate (school j)
2979+
^
2980+
5: }
2981+
6: parameters {
2982+
-------------------------------------------------
2983+
2984+
Unicode identifiers are not supported without the (experimental) allow-unicode flag
29722985
[exit 1]
29732986
$ ../../../../install/default/bin/stanc validate_add_expression_dimss_bad.stan
29742987
Semantic error in 'validate_add_expression_dimss_bad.stan', line 4, column 6 to column 13:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
data {
2+
int<lower=0> J; // number of schools
3+
array[J] real y; // estimated treatment effect (school j)
4+
array[J] real<lower=0> σ; // std err of effect estimate (school j)
5+
}
6+
parameters {
7+
real μ;
8+
array[J] real θ;
9+
real<lower=0> τ;
10+
}
11+
model {
12+
θ ~ normal(μ, τ);
13+
y ~ normal(θ, σ);
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data {
2+
int ñ߿;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data {
2+
int _ñ;
3+
}
18 Bytes
Binary file not shown.
388 Bytes
Binary file not shown.

test/integration/good/code-gen/cpp.expected

Lines changed: 564 additions & 82 deletions
Large diffs are not rendered by default.

test/integration/good/code-gen/dune

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
(action
88
(with-stdout-to
99
%{targets}
10-
(run %{bin:run_bin_on_args} "%{bin:stanc} --print-cpp" %{stanfiles}))))
10+
(run
11+
%{bin:run_bin_on_args}
12+
"%{bin:stanc} --allow-unicode --print-cpp"
13+
%{stanfiles}))))
1114

1215
(rule
1316
(alias runtest)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
data {
2+
int<lower=0> J; // number of schools
3+
array[J] real y; // estimated treatment effect (school j)
4+
array[J] real<lower=0> σ; // std err of effect estimate (school j)
5+
}
6+
parameters {
7+
real μ;
8+
array[J] real θ;
9+
real<lower=0> τ;
10+
}
11+
model {
12+
θ ~ normal(μ, τ);
13+
y ~ normal(θ, σ);
14+
15+
}
16+
17+
18+
generated quantities {
19+
int ñabc;
20+
ñabc = 1 + to_int(θ[J-1]);
21+
print(ñabc);
22+
}

0 commit comments

Comments
 (0)