Skip to content

Commit 00870e8

Browse files
sbarzowskijohnbartholomew
authored andcommitted
Add regression test for locale affecting output
See #722
1 parent dee145a commit 00870e8

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ libjsonnet++.so
1919
libjsonnet++.so.*
2020
libjsonnet_test_file
2121
libjsonnet_test_snippet
22+
libjsonnet_test_locale
2223
**/core.*
2324
**/vgcore
2425
**/vgcore.*

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ install: bins libs
133133

134134
all: $(ALL)
135135

136-
test: jsonnet jsonnetfmt libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file
136+
test: jsonnet jsonnetfmt libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file libjsonnet_test_locale
137137
./tests.sh
138138

139139
reformat:
@@ -146,7 +146,8 @@ MAKEDEPEND_SRCS = \
146146
cmd/jsonnet.cpp \
147147
cmd/jsonnetfmt.cpp \
148148
core/libjsonnet_test_snippet.c \
149-
core/libjsonnet_test_file.c
149+
core/libjsonnet_test_file.c \
150+
core/libjsonnet_test_locale.cpp
150151

151152
depend: core/std.jsonnet.h
152153
rm -f Makefile.depend
@@ -196,6 +197,14 @@ LIBJSONNET_TEST_FILE_SRCS = \
196197
libjsonnet_test_file: $(LIBJSONNET_TEST_FILE_SRCS)
197198
$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -ljsonnet -o $@
198199

200+
LIBJSONNET_TEST_LOCALE_SRCS = \
201+
core/libjsonnet_test_locale.cpp \
202+
libjsonnet++.so \
203+
include/libjsonnet++.h
204+
205+
libjsonnet_test_locale: $(LIBJSONNET_TEST_LOCALE_SRCS)
206+
$(CXX) $(CXXFLAGS) $(LDFLAGS) $< -L. -ljsonnet++ -o $@
207+
199208
# Encode standard library for embedding in C
200209
core/%.jsonnet.h: stdlib/%.jsonnet
201210
(($(OD) -v -Anone -t u1 $< \

core/libjsonnet_test_locale.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <locale>
3+
#include <cassert>
4+
#include <libjsonnet++.h>
5+
6+
// Regression test for the follwing issue: https://github.com/google/jsonnet/issues/722
7+
8+
int main() {
9+
std::string templatedJSONString { "2000" };
10+
std::locale glocale("en_US.UTF-8");
11+
std::locale::global(glocale);
12+
13+
jsonnet::Jsonnet jsonnet {};
14+
jsonnet.init();
15+
16+
std::string expanded;
17+
if (!jsonnet.evaluateSnippet("", templatedJSONString, &expanded)) {
18+
std::cerr << "Error parsing Jsonnet: "+jsonnet.lastError();
19+
exit(1);
20+
}
21+
std::string expected = "2000\n";
22+
assert(expected == expanded);
23+
return 0;
24+
}

tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ if [ -z "$DISABLE_LIB_TESTS" ]; then
1111
LD_LIBRARY_PATH=. ./libjsonnet_test_snippet "${TEST_SNIPPET}" || FAIL=TRUE
1212
printf 'libjsonnet_test_file: '
1313
LD_LIBRARY_PATH=. ./libjsonnet_test_file "test_suite/object.jsonnet" || FAIL=TRUE
14+
echo -n 'libjsonnet_test_locale: '
15+
LD_LIBRARY_PATH=. ./libjsonnet_test_locale || FAIL=TRUE
1416
fi
1517
examples/check.sh || FAIL=TRUE
1618
examples/terraform/check.sh || FAIL=TRUE

0 commit comments

Comments
 (0)