jsonnet 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -6
- data/README.md +1 -1
- data/ext/jsonnet/extconf.rb +4 -2
- data/ext/jsonnet/vm.c +167 -10
- data/jsonnet.gemspec +4 -4
- data/lib/jsonnet/version.rb +1 -1
- data/lib/jsonnet/vm.rb +38 -10
- data/test/test_jsonnet.rb +1 -1
- data/test/test_vm.rb +90 -0
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2872d26e221e6ec8bbd30265edd0109eb9f1c68fa19fcfaa888c9921f096f771
|
4
|
+
data.tar.gz: b91f326aa5a64a97f9f088a17b6462e8cf77d8e82679c11231cc68eff2b495e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dab85234e40a4b05ae60a4fe7423af108df27b9e3d2db119e6d18edb40f9abbb92c20a5cf7c25fb5d20e3a090031fae42ec93fab135ea3c6682adaf3ec006693
|
7
|
+
data.tar.gz: 8aea3bbab4b7661a4ee6d055bd6fdd9b5c0834feae98f266b5d162563b860b932689f4fcd4096a3f2dcdf12fb5e960b2fbb7f7e65ce23d1d177d5f85128dbb56
|
data/.travis.yml
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
language: ruby
|
2
|
-
dist:
|
2
|
+
dist: xenial
|
3
3
|
script: bundle exec rake test
|
4
4
|
|
5
5
|
matrix:
|
6
6
|
include:
|
7
7
|
- os: linux
|
8
|
-
rvm: 2.
|
8
|
+
rvm: 2.5.8
|
9
9
|
- os: osx
|
10
|
-
rvm: 2.
|
10
|
+
rvm: 2.5.8
|
11
11
|
- os: linux
|
12
|
-
rvm: 2.
|
12
|
+
rvm: 2.6.6
|
13
13
|
- os: osx
|
14
|
-
rvm: 2.
|
14
|
+
rvm: 2.6.6
|
15
|
+
- os: linux
|
16
|
+
rvm: 2.7.2
|
17
|
+
- os: osx
|
18
|
+
rvm: 2.7.2
|
15
19
|
fast_finish: true
|
16
|
-
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
24
24
|
$ gem install jsonnet
|
25
25
|
```
|
26
26
|
|
27
|
-
By default this gem will compile and install Jsonnet (v0.
|
27
|
+
By default this gem will compile and install Jsonnet (v0.16.0) as part of
|
28
28
|
installation. However you can use the system version of Jsonnet if you prefer.
|
29
29
|
This would be the recommended route if you want to use a different version
|
30
30
|
of Jsonnet or are having problems installing this.
|
data/ext/jsonnet/extconf.rb
CHANGED
@@ -13,8 +13,8 @@ unless using_system_libraries?
|
|
13
13
|
require 'mini_portile2'
|
14
14
|
message "Using mini_portile version #{MiniPortile::VERSION}\n"
|
15
15
|
|
16
|
-
recipe = MiniPortile.new('jsonnet', 'v0.
|
17
|
-
recipe.files = ['https://github.com/google/jsonnet/archive/v0.
|
16
|
+
recipe = MiniPortile.new('jsonnet', 'v0.17.0')
|
17
|
+
recipe.files = ['https://github.com/google/jsonnet/archive/v0.17.0.tar.gz']
|
18
18
|
class << recipe
|
19
19
|
|
20
20
|
def compile
|
@@ -39,6 +39,7 @@ unless using_system_libraries?
|
|
39
39
|
|
40
40
|
FileUtils.cp(File.join(work_path, 'libjsonnet.a'), lib_path)
|
41
41
|
FileUtils.cp(File.join(work_path, 'include', 'libjsonnet.h'), include_path)
|
42
|
+
FileUtils.cp(File.join(work_path, 'include', 'libjsonnet_fmt.h'), include_path)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -57,4 +58,5 @@ end
|
|
57
58
|
|
58
59
|
abort 'libjsonnet.h not found' unless have_header('libjsonnet.h')
|
59
60
|
abort 'libjsonnet not found' unless have_library('jsonnet')
|
61
|
+
have_header('libjsonnet_fmt.h')
|
60
62
|
create_makefile('jsonnet/jsonnet_wrap')
|
data/ext/jsonnet/vm.c
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
#include <libjsonnet.h>
|
2
|
+
#ifdef HAVE_LIBJSONNET_FMT_H
|
3
|
+
# include <libjsonnet_fmt.h>
|
4
|
+
#endif
|
2
5
|
#include <ruby/ruby.h>
|
3
6
|
#include <ruby/intern.h>
|
4
7
|
|
@@ -20,8 +23,10 @@ static VALUE cVM;
|
|
20
23
|
* Raised on evaluation errors in a Jsonnet VM.
|
21
24
|
*/
|
22
25
|
static VALUE eEvaluationError;
|
26
|
+
static VALUE eFormatError;
|
23
27
|
|
24
28
|
static void raise_eval_error(struct JsonnetVm *vm, char *msg, rb_encoding *enc);
|
29
|
+
static void raise_format_error(struct JsonnetVm *vm, char *msg, rb_encoding *enc);
|
25
30
|
static VALUE str_new_json(struct JsonnetVm *vm, char *json, rb_encoding *enc);
|
26
31
|
static VALUE fileset_new(struct JsonnetVm *vm, char *buf, rb_encoding *enc);
|
27
32
|
|
@@ -255,6 +260,128 @@ vm_set_max_trace(VALUE self, VALUE val)
|
|
255
260
|
return Qnil;
|
256
261
|
}
|
257
262
|
|
263
|
+
static VALUE
|
264
|
+
vm_set_fmt_indent(VALUE self, VALUE val)
|
265
|
+
{
|
266
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
267
|
+
jsonnet_fmt_indent(vm->vm, NUM2INT(val));
|
268
|
+
return val;
|
269
|
+
}
|
270
|
+
|
271
|
+
static VALUE
|
272
|
+
vm_set_fmt_max_blank_lines(VALUE self, VALUE val)
|
273
|
+
{
|
274
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
275
|
+
jsonnet_fmt_max_blank_lines(vm->vm, NUM2INT(val));
|
276
|
+
return val;
|
277
|
+
}
|
278
|
+
|
279
|
+
static VALUE
|
280
|
+
vm_set_fmt_string(VALUE self, VALUE str)
|
281
|
+
{
|
282
|
+
const char *ptr;
|
283
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
284
|
+
StringValue(str);
|
285
|
+
if (RSTRING_LEN(str) != 1) {
|
286
|
+
rb_raise(rb_eArgError, "fmt_string must have a length of 1");
|
287
|
+
}
|
288
|
+
ptr = RSTRING_PTR(str);
|
289
|
+
switch (*ptr) {
|
290
|
+
case 'd':
|
291
|
+
case 's':
|
292
|
+
case 'l':
|
293
|
+
jsonnet_fmt_string(vm->vm, *ptr);
|
294
|
+
return str;
|
295
|
+
default:
|
296
|
+
rb_raise(rb_eArgError, "fmt_string only accepts 'd', 's', or 'l'");
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
static VALUE
|
301
|
+
vm_set_fmt_comment(VALUE self, VALUE str)
|
302
|
+
{
|
303
|
+
const char *ptr;
|
304
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
305
|
+
StringValue(str);
|
306
|
+
if (RSTRING_LEN(str) != 1) {
|
307
|
+
rb_raise(rb_eArgError, "fmt_comment must have a length of 1");
|
308
|
+
}
|
309
|
+
ptr = RSTRING_PTR(str);
|
310
|
+
switch (*ptr) {
|
311
|
+
case 'h':
|
312
|
+
case 's':
|
313
|
+
case 'l':
|
314
|
+
jsonnet_fmt_comment(vm->vm, *ptr);
|
315
|
+
return str;
|
316
|
+
default:
|
317
|
+
rb_raise(rb_eArgError, "fmt_comment only accepts 'h', 's', or 'l'");
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
static VALUE
|
322
|
+
vm_set_fmt_pad_arrays(VALUE self, VALUE val)
|
323
|
+
{
|
324
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
325
|
+
jsonnet_fmt_pad_objects(vm->vm, RTEST(val) ? 1 : 0);
|
326
|
+
return val;
|
327
|
+
}
|
328
|
+
|
329
|
+
static VALUE
|
330
|
+
vm_set_fmt_pad_objects(VALUE self, VALUE val)
|
331
|
+
{
|
332
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
333
|
+
jsonnet_fmt_pad_objects(vm->vm, RTEST(val) ? 1 : 0);
|
334
|
+
return val;
|
335
|
+
}
|
336
|
+
|
337
|
+
static VALUE
|
338
|
+
vm_set_fmt_pretty_field_names(VALUE self, VALUE val)
|
339
|
+
{
|
340
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
341
|
+
jsonnet_fmt_pretty_field_names(vm->vm, RTEST(val) ? 1 : 0);
|
342
|
+
return val;
|
343
|
+
}
|
344
|
+
|
345
|
+
static VALUE
|
346
|
+
vm_set_fmt_sort_imports(VALUE self, VALUE val)
|
347
|
+
{
|
348
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
349
|
+
jsonnet_fmt_sort_imports(vm->vm, RTEST(val) ? 1 : 0);
|
350
|
+
return val;
|
351
|
+
}
|
352
|
+
|
353
|
+
static VALUE
|
354
|
+
vm_fmt_file(VALUE self, VALUE fname, VALUE encoding)
|
355
|
+
{
|
356
|
+
int error;
|
357
|
+
char *result;
|
358
|
+
rb_encoding *const enc = rb_to_encoding(encoding);
|
359
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
360
|
+
|
361
|
+
FilePathValue(fname);
|
362
|
+
result = jsonnet_fmt_file(vm->vm, StringValueCStr(fname), &error);
|
363
|
+
if (error) {
|
364
|
+
raise_format_error(vm->vm, result, rb_enc_get(fname));
|
365
|
+
}
|
366
|
+
return str_new_json(vm->vm, result, enc);
|
367
|
+
}
|
368
|
+
|
369
|
+
static VALUE
|
370
|
+
vm_fmt_snippet(VALUE self, VALUE snippet, VALUE fname)
|
371
|
+
{
|
372
|
+
int error;
|
373
|
+
char *result;
|
374
|
+
struct jsonnet_vm_wrap *vm = rubyjsonnet_obj_to_vm(self);
|
375
|
+
|
376
|
+
rb_encoding *enc = rubyjsonnet_assert_asciicompat(StringValue(snippet));
|
377
|
+
FilePathValue(fname);
|
378
|
+
result = jsonnet_fmt_snippet(vm->vm, StringValueCStr(fname), StringValueCStr(snippet), &error);
|
379
|
+
if (error) {
|
380
|
+
raise_format_error(vm->vm, result, rb_enc_get(fname));
|
381
|
+
}
|
382
|
+
return str_new_json(vm->vm, result, enc);
|
383
|
+
}
|
384
|
+
|
258
385
|
void
|
259
386
|
rubyjsonnet_init_vm(VALUE mJsonnet)
|
260
387
|
{
|
@@ -262,6 +389,8 @@ rubyjsonnet_init_vm(VALUE mJsonnet)
|
|
262
389
|
rb_define_singleton_method(cVM, "new", vm_s_new, -1);
|
263
390
|
rb_define_private_method(cVM, "eval_file", vm_evaluate_file, 3);
|
264
391
|
rb_define_private_method(cVM, "eval_snippet", vm_evaluate, 3);
|
392
|
+
rb_define_private_method(cVM, "fmt_file", vm_fmt_file, 2);
|
393
|
+
rb_define_private_method(cVM, "fmt_snippet", vm_fmt_snippet, 2);
|
265
394
|
rb_define_method(cVM, "ext_var", vm_ext_var, 2);
|
266
395
|
rb_define_method(cVM, "ext_code", vm_ext_code, 2);
|
267
396
|
rb_define_method(cVM, "tla_var", vm_tla_var, 2);
|
@@ -272,22 +401,30 @@ rubyjsonnet_init_vm(VALUE mJsonnet)
|
|
272
401
|
rb_define_method(cVM, "gc_growth_trigger=", vm_set_gc_growth_trigger, 1);
|
273
402
|
rb_define_method(cVM, "string_output=", vm_set_string_output, 1);
|
274
403
|
rb_define_method(cVM, "max_trace=", vm_set_max_trace, 1);
|
404
|
+
rb_define_method(cVM, "fmt_indent=", vm_set_fmt_indent, 1);
|
405
|
+
rb_define_method(cVM, "fmt_max_blank_lines=", vm_set_fmt_max_blank_lines, 1);
|
406
|
+
rb_define_method(cVM, "fmt_string=", vm_set_fmt_string, 1);
|
407
|
+
rb_define_method(cVM, "fmt_comment=", vm_set_fmt_comment, 1);
|
408
|
+
rb_define_method(cVM, "fmt_pad_arrays=", vm_set_fmt_pad_arrays, 1);
|
409
|
+
rb_define_method(cVM, "fmt_pad_objects=", vm_set_fmt_pad_objects, 1);
|
410
|
+
rb_define_method(cVM, "fmt_pretty_field_names=", vm_set_fmt_pretty_field_names, 1);
|
411
|
+
rb_define_method(cVM, "fmt_sort_imports=", vm_set_fmt_sort_imports, 1);
|
412
|
+
|
413
|
+
rb_define_const(mJsonnet, "STRING_STYLE_DOUBLE", rb_str_new_cstr("d"));
|
414
|
+
rb_define_const(mJsonnet, "STRING_STYLE_SINGLE", rb_str_new_cstr("s"));
|
415
|
+
rb_define_const(mJsonnet, "STRING_STYLE_LEAVE", rb_str_new_cstr("l"));
|
416
|
+
rb_define_const(mJsonnet, "COMMENT_STYLE_HASH", rb_str_new_cstr("h"));
|
417
|
+
rb_define_const(mJsonnet, "COMMENT_STYLE_SLASH", rb_str_new_cstr("s"));
|
418
|
+
rb_define_const(mJsonnet, "COMMENT_STYLE_LEAVE", rb_str_new_cstr("l"));
|
275
419
|
|
276
420
|
rubyjsonnet_init_callbacks(cVM);
|
277
421
|
|
278
422
|
eEvaluationError = rb_define_class_under(mJsonnet, "EvaluationError", rb_eRuntimeError);
|
423
|
+
eFormatError = rb_define_class_under(mJsonnet, "FormatError", rb_eRuntimeError);
|
279
424
|
}
|
280
425
|
|
281
|
-
/**
|
282
|
-
* raises an EvaluationError whose message is \c msg.
|
283
|
-
* @param[in] vm a JsonnetVM
|
284
|
-
* @param[in] msg must be a NUL-terminated string returned by \c vm.
|
285
|
-
* @return never returns
|
286
|
-
* @throw EvaluationError
|
287
|
-
* @sa rescue_callback
|
288
|
-
*/
|
289
426
|
static void
|
290
|
-
|
427
|
+
raise_error(VALUE exception_class, struct JsonnetVm *vm, char *msg, rb_encoding *enc)
|
291
428
|
{
|
292
429
|
VALUE ex;
|
293
430
|
const int state = rubyjsonnet_jump_tag(msg);
|
@@ -300,11 +437,31 @@ raise_eval_error(struct JsonnetVm *vm, char *msg, rb_encoding *enc)
|
|
300
437
|
rb_jump_tag(state);
|
301
438
|
}
|
302
439
|
|
303
|
-
ex = rb_exc_new3(
|
440
|
+
ex = rb_exc_new3(exception_class, rb_enc_str_new_cstr(msg, enc));
|
304
441
|
jsonnet_realloc(vm, msg, 0);
|
305
442
|
rb_exc_raise(ex);
|
306
443
|
}
|
307
444
|
|
445
|
+
/**
|
446
|
+
* raises an EvaluationError whose message is \c msg.
|
447
|
+
* @param[in] vm a JsonnetVM
|
448
|
+
* @param[in] msg must be a NUL-terminated string returned by \c vm.
|
449
|
+
* @return never returns
|
450
|
+
* @throw EvaluationError
|
451
|
+
* @sa rescue_callback
|
452
|
+
*/
|
453
|
+
static void
|
454
|
+
raise_eval_error(struct JsonnetVm *vm, char *msg, rb_encoding *enc)
|
455
|
+
{
|
456
|
+
raise_error(eEvaluationError, vm, msg, enc);
|
457
|
+
}
|
458
|
+
|
459
|
+
static void
|
460
|
+
raise_format_error(struct JsonnetVm *vm, char *msg, rb_encoding *enc)
|
461
|
+
{
|
462
|
+
raise_error(eFormatError, vm, msg, enc);
|
463
|
+
}
|
464
|
+
|
308
465
|
/**
|
309
466
|
* Returns a String whose contents is equal to \c json.
|
310
467
|
* It automatically frees \c json just after constructing the return value.
|
data/jsonnet.gemspec
CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "mini_portile2", ">= 2.2.0"
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "
|
25
|
-
spec.add_development_dependency "rake", "
|
26
|
-
spec.add_development_dependency "test-unit", "
|
27
|
-
spec.add_development_dependency "rake-compiler", "
|
24
|
+
spec.add_development_dependency "bundler", ">= 1.7"
|
25
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
26
|
+
spec.add_development_dependency "test-unit", ">= 3.1.3"
|
27
|
+
spec.add_development_dependency "rake-compiler", ">= 0.9.5"
|
28
28
|
end
|
data/lib/jsonnet/version.rb
CHANGED
data/lib/jsonnet/vm.rb
CHANGED
@@ -14,9 +14,9 @@ module Jsonnet
|
|
14
14
|
# @see #evaluate
|
15
15
|
def evaluate(snippet, options = {})
|
16
16
|
snippet_check = ->(key, value) { key.to_s.match(/^filename|multi$/) }
|
17
|
-
snippet_options = options.select
|
18
|
-
vm_options = options.reject
|
19
|
-
new(vm_options).evaluate(snippet, snippet_options)
|
17
|
+
snippet_options = options.select(&snippet_check)
|
18
|
+
vm_options = options.reject(&snippet_check)
|
19
|
+
new(vm_options).evaluate(snippet, **snippet_options)
|
20
20
|
end
|
21
21
|
|
22
22
|
##
|
@@ -30,9 +30,9 @@ module Jsonnet
|
|
30
30
|
# @see #evaluate_file
|
31
31
|
def evaluate_file(filename, options = {})
|
32
32
|
file_check = ->(key, value) { key.to_s.match(/^encoding|multi$/) }
|
33
|
-
file_options = options.select
|
34
|
-
vm_options = options.reject
|
35
|
-
new(vm_options).evaluate_file(filename, file_options)
|
33
|
+
file_options = options.select(&file_check)
|
34
|
+
vm_options = options.reject(&file_check)
|
35
|
+
new(vm_options).evaluate_file(filename, **file_options)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -88,14 +88,39 @@ module Jsonnet
|
|
88
88
|
eval_file(filename, encoding, multi)
|
89
89
|
end
|
90
90
|
|
91
|
+
##
|
92
|
+
# Format Jsonnet file.
|
93
|
+
#
|
94
|
+
# @param [String] filename filename of a Jsonnet source file.
|
95
|
+
# @return [String] a formatted Jsonnet representation
|
96
|
+
# @raise [FormatError] raised when the formatting results an error.
|
97
|
+
def format_file(filename, encoding: Encoding.default_external)
|
98
|
+
fmt_file(filename, encoding)
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Format Jsonnet snippet.
|
103
|
+
#
|
104
|
+
# @param [String] jsonnet Jsonnet source string. Must be encoded in ASCII-compatible encoding.
|
105
|
+
# @param [String] filename filename of the source. Used in stacktrace.
|
106
|
+
# @return [String] a formatted Jsonnet representation
|
107
|
+
# @raise [FormatError] raised when the formatting results an error.
|
108
|
+
# @raise [UnsupportedEncodingError] raised when the encoding of jsonnt is not ASCII-compatible.
|
109
|
+
def format(jsonnet, filename: "(jsonnet)")
|
110
|
+
fmt_snippet(jsonnet, filename)
|
111
|
+
end
|
112
|
+
|
91
113
|
##
|
92
114
|
# Lets the given block handle "import" expression of Jsonnet.
|
93
115
|
# @yieldparam [String] base base path to resolve "rel" from.
|
94
116
|
# @yieldparam [String] rel a relative or absolute path to the file to be imported
|
95
117
|
# @yieldreturn [Array<String>] a pair of the content of the imported file and
|
96
118
|
# its path.
|
97
|
-
def handle_import
|
98
|
-
|
119
|
+
def handle_import(&block)
|
120
|
+
if block.nil?
|
121
|
+
raise ArgumentError, 'handle_import requires a block'
|
122
|
+
end
|
123
|
+
self.import_callback = to_method(block)
|
99
124
|
nil
|
100
125
|
end
|
101
126
|
|
@@ -112,8 +137,11 @@ module Jsonnet
|
|
112
137
|
# Also all the positional optional parameters of the body are interpreted
|
113
138
|
# as required parameters. And the body cannot have keyword, rest or
|
114
139
|
# keyword rest paramters.
|
115
|
-
def define_function(name, body = nil)
|
116
|
-
body = body ? body.to_proc :
|
140
|
+
def define_function(name, body = nil, &block)
|
141
|
+
body = body ? body.to_proc : block
|
142
|
+
if body.nil?
|
143
|
+
raise ArgumentError, 'define_function requires a body argument or a block'
|
144
|
+
end
|
117
145
|
params = body.parameters.map.with_index do |(type, name), i|
|
118
146
|
raise ArgumentError, "rest or keyword parameters are not allowed: #{type}" \
|
119
147
|
unless [:req, :opt].include? type
|
data/test/test_jsonnet.rb
CHANGED
data/test/test_vm.rb
CHANGED
@@ -474,6 +474,96 @@ class TestVM < Test::Unit::TestCase
|
|
474
474
|
end
|
475
475
|
end
|
476
476
|
|
477
|
+
test "Jsonnet::VM#format_file formats Jsonnet file" do
|
478
|
+
vm = Jsonnet::VM.new
|
479
|
+
vm.fmt_indent = 4
|
480
|
+
with_example_file(%<
|
481
|
+
local myvar = 1;
|
482
|
+
{
|
483
|
+
"foo": myvar
|
484
|
+
}
|
485
|
+
>) {|fname|
|
486
|
+
result = vm.format_file(fname)
|
487
|
+
assert_equal <<-EOS, result
|
488
|
+
local myvar = 1;
|
489
|
+
{
|
490
|
+
foo: myvar,
|
491
|
+
}
|
492
|
+
EOS
|
493
|
+
}
|
494
|
+
end
|
495
|
+
|
496
|
+
test "Jsonnet::VM#format formats Jsonnet snippet" do
|
497
|
+
vm = Jsonnet::VM.new
|
498
|
+
vm.fmt_string = 'd'
|
499
|
+
result = vm.format(<<-EOS)
|
500
|
+
local myvar = 'myvar';
|
501
|
+
{
|
502
|
+
foo: [myvar,myvar]
|
503
|
+
}
|
504
|
+
EOS
|
505
|
+
assert_equal <<-EOS, result
|
506
|
+
local myvar = "myvar";
|
507
|
+
{
|
508
|
+
foo: [myvar, myvar],
|
509
|
+
}
|
510
|
+
EOS
|
511
|
+
end
|
512
|
+
|
513
|
+
test "Jsonnet::VM#fmt_string only accepts 'd', 's', or 'l'" do
|
514
|
+
vm = Jsonnet::VM.new
|
515
|
+
vm.fmt_string = Jsonnet::STRING_STYLE_DOUBLE
|
516
|
+
vm.fmt_string = Jsonnet::STRING_STYLE_SINGLE
|
517
|
+
vm.fmt_string = Jsonnet::STRING_STYLE_LEAVE
|
518
|
+
assert_raise(ArgumentError) do
|
519
|
+
vm.fmt_string = ''
|
520
|
+
end
|
521
|
+
assert_raise(ArgumentError) do
|
522
|
+
vm.fmt_string = 'a'
|
523
|
+
end
|
524
|
+
assert_raise(ArgumentError) do
|
525
|
+
vm.fmt_string = 'ds'
|
526
|
+
end
|
527
|
+
assert_raise(TypeError) do
|
528
|
+
vm.fmt_string = 0
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
test "Jsonnet::VM#fmt_comment only accepts 'h', 's', or 'l'" do
|
533
|
+
vm = Jsonnet::VM.new
|
534
|
+
vm.fmt_comment = Jsonnet::COMMENT_STYLE_HASH
|
535
|
+
vm.fmt_comment = Jsonnet::COMMENT_STYLE_SLASH
|
536
|
+
vm.fmt_comment = Jsonnet::COMMENT_STYLE_LEAVE
|
537
|
+
assert_raise(ArgumentError) do
|
538
|
+
vm.fmt_comment = ''
|
539
|
+
end
|
540
|
+
assert_raise(ArgumentError) do
|
541
|
+
vm.fmt_comment = 'a'
|
542
|
+
end
|
543
|
+
assert_raise(ArgumentError) do
|
544
|
+
vm.fmt_comment = 'hs'
|
545
|
+
end
|
546
|
+
assert_raise(TypeError) do
|
547
|
+
vm.fmt_comment = 0
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
test "Jsonnet::VM#fmt_file raises FormatError on error" do
|
552
|
+
vm = Jsonnet::VM.new
|
553
|
+
with_example_file('{foo: }') do |fname|
|
554
|
+
assert_raise(Jsonnet::FormatError) do
|
555
|
+
vm.format_file(fname)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
test "Jsonnet::VM#fmt_snippet raises FormatError on error" do
|
561
|
+
vm = Jsonnet::VM.new
|
562
|
+
assert_raise(Jsonnet::FormatError) do
|
563
|
+
vm.format('{foo: }')
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
477
567
|
private
|
478
568
|
def with_example_file(content)
|
479
569
|
Tempfile.open("example.jsonnet") {|f|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Yugui Sonoda
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini_portile2
|
@@ -28,56 +28,56 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: test-unit
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 3.1.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.1.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake-compiler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.9.5
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.9.5
|
83
83
|
description: Wraps the official C++ implementation of Jsonnet
|
@@ -114,7 +114,7 @@ homepage: ''
|
|
114
114
|
licenses:
|
115
115
|
- MIT
|
116
116
|
metadata: {}
|
117
|
-
post_install_message:
|
117
|
+
post_install_message:
|
118
118
|
rdoc_options: []
|
119
119
|
require_paths:
|
120
120
|
- lib
|
@@ -129,9 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
|
-
|
133
|
-
|
134
|
-
signing_key:
|
132
|
+
rubygems_version: 3.1.2
|
133
|
+
signing_key:
|
135
134
|
specification_version: 4
|
136
135
|
summary: Jsonnet library
|
137
136
|
test_files:
|