Skip to content

Commit

Permalink
Add regression test for locale affecting output
Browse files Browse the repository at this point in the history
See #722
  • Loading branch information
sbarzowski committed Nov 3, 2019
1 parent e8aa025 commit a793333
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ libjsonnet++.so.*
libjsonnet.js
libjsonnet_test_file
libjsonnet_test_snippet
libjsonnet_test_locale
**/core.*
**/vgcore
**/vgcore.*
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ LIBS = \
ALL = \
libjsonnet_test_snippet \
libjsonnet_test_file \
libjsonnet_test_locale \
libjsonnet.js \
doc/js/libjsonnet.js \
$(BINS) \
Expand Down Expand Up @@ -135,7 +136,7 @@ install: bins libs

all: $(ALL)

test: jsonnet jsonnetfmt libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file
test: jsonnet jsonnetfmt libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file libjsonnet_test_locale
./tests.sh

reformat:
Expand All @@ -148,7 +149,8 @@ MAKEDEPEND_SRCS = \
cmd/jsonnet.cpp \
cmd/jsonnetfmt.cpp \
core/libjsonnet_test_snippet.c \
core/libjsonnet_test_file.c
core/libjsonnet_test_file.c \
core/libjsonnet_test_locale.cpp

depend: core/std.jsonnet.h
rm -f Makefile.depend
Expand Down Expand Up @@ -211,6 +213,14 @@ LIBJSONNET_TEST_FILE_SRCS = \
libjsonnet_test_file: $(LIBJSONNET_TEST_FILE_SRCS)
$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -ljsonnet -o $@

LIBJSONNET_TEST_LOCALE_SRCS = \
core/libjsonnet_test_locale.cpp \
libjsonnet++.so \
include/libjsonnet++.h

libjsonnet_test_locale: $(LIBJSONNET_TEST_LOCALE_SRCS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $< -L. -ljsonnet++ -o $@

# Encode standard library for embedding in C
core/%.jsonnet.h: stdlib/%.jsonnet
(($(OD) -v -Anone -t u1 $< \
Expand Down
24 changes: 24 additions & 0 deletions core/libjsonnet_test_locale.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <locale>
#include <cassert>
#include <libjsonnet++.h>

// Regression test for the follwing issue: https://github.com/google/jsonnet/issues/722

int main() {
std::string templatedJSONString { "2000" };
std::locale glocale("en_US.UTF-8");
std::locale::global(glocale);

jsonnet::Jsonnet jsonnet {};
jsonnet.init();

std::string expanded;
if (!jsonnet.evaluateSnippet("", templatedJSONString, &expanded)) {
std::cerr << "Error parsing Jsonnet: "+jsonnet.lastError();
exit(1);
}
std::string expected = "2000\n";
assert(expected == expanded);
return 0;
}
2 changes: 2 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if [ -z "$DISABLE_LIB_TESTS" ]; then
LD_LIBRARY_PATH=. ./libjsonnet_test_snippet "${TEST_SNIPPET}" || FAIL=TRUE
echo -n 'libjsonnet_test_file: '
LD_LIBRARY_PATH=. ./libjsonnet_test_file "test_suite/object.jsonnet" || FAIL=TRUE
echo -n 'libjsonnet_test_locale: '
LD_LIBRARY_PATH=. ./libjsonnet_test_locale || FAIL=TRUE
fi
examples/check.sh || FAIL=TRUE
examples/terraform/check.sh || FAIL=TRUE
Expand Down

0 comments on commit a793333

Please sign in to comment.