redsnow 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -1
  3. data/README.md +12 -0
  4. data/ext/snowcrash/bin/snowcrash +0 -0
  5. data/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.c +5 -2
  6. data/ext/snowcrash/snowcrash.gyp +7 -2
  7. data/ext/snowcrash/src/ActionParser.h +141 -81
  8. data/ext/snowcrash/src/AssetParser.h +19 -11
  9. data/ext/snowcrash/src/Blueprint.h +44 -14
  10. data/ext/snowcrash/src/BlueprintParser.h +65 -51
  11. data/ext/snowcrash/src/BlueprintSourcemap.h +254 -0
  12. data/ext/snowcrash/src/BlueprintUtility.h +3 -24
  13. data/ext/snowcrash/src/CBlueprint.cc +40 -31
  14. data/ext/snowcrash/src/CBlueprint.h +54 -58
  15. data/ext/snowcrash/src/CBlueprintSourcemap.cc +620 -0
  16. data/ext/snowcrash/src/CBlueprintSourcemap.h +342 -0
  17. data/ext/snowcrash/src/CSourceAnnotation.cc +14 -0
  18. data/ext/snowcrash/src/CodeBlockUtility.h +42 -5
  19. data/ext/snowcrash/src/HeadersParser.h +84 -42
  20. data/ext/snowcrash/src/ParameterParser.h +110 -68
  21. data/ext/snowcrash/src/ParametersParser.h +26 -28
  22. data/ext/snowcrash/src/PayloadParser.h +164 -83
  23. data/ext/snowcrash/src/ResourceGroupParser.h +35 -41
  24. data/ext/snowcrash/src/ResourceParser.h +142 -97
  25. data/ext/snowcrash/src/SectionParser.h +15 -14
  26. data/ext/snowcrash/src/SectionParserData.h +11 -2
  27. data/ext/snowcrash/src/SectionProcessor.h +42 -18
  28. data/ext/snowcrash/src/Serialize.cc +2 -0
  29. data/ext/snowcrash/src/Serialize.h +3 -1
  30. data/ext/snowcrash/src/SerializeJSON.cc +608 -16
  31. data/ext/snowcrash/src/SerializeJSON.h +4 -1
  32. data/ext/snowcrash/src/SerializeYAML.cc +367 -19
  33. data/ext/snowcrash/src/SerializeYAML.h +4 -1
  34. data/ext/snowcrash/src/SymbolTable.h +12 -1
  35. data/ext/snowcrash/src/ValuesParser.h +12 -11
  36. data/ext/snowcrash/src/Version.h +1 -1
  37. data/ext/snowcrash/src/csnowcrash.cc +7 -3
  38. data/ext/snowcrash/src/csnowcrash.h +4 -2
  39. data/ext/snowcrash/src/snowcrash.cc +10 -11
  40. data/ext/snowcrash/src/snowcrash.h +3 -3
  41. data/ext/snowcrash/src/snowcrash/snowcrash.cc +38 -8
  42. data/ext/snowcrash/tools/homebrew/snowcrash.rb +1 -1
  43. data/lib/redsnow.rb +41 -2
  44. data/lib/redsnow/binding.rb +93 -8
  45. data/lib/redsnow/blueprint.rb +48 -25
  46. data/lib/redsnow/parseresult.rb +9 -2
  47. data/lib/redsnow/sourcemap.rb +369 -0
  48. data/lib/redsnow/version.rb +1 -1
  49. data/test/fixtures/sample-api-ast.json +1 -1
  50. data/test/fixtures/sample-api-sourcemap.json +169 -0
  51. data/test/redsnow_binding_test.rb +19 -2
  52. data/test/redsnow_options_test.rb +42 -0
  53. data/test/redsnow_parseresult_test.rb +5 -1
  54. data/test/redsnow_test.rb +5 -0
  55. metadata +11 -2
@@ -1,4 +1,4 @@
1
1
  module RedSnow
2
2
  # Gem version
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
@@ -1,5 +1,5 @@
1
1
  {
2
- "_version": "2.0",
2
+ "_version": "2.1",
3
3
  "metadata": [
4
4
  {
5
5
  "name": "FORMAT",
@@ -0,0 +1,169 @@
1
+ {
2
+ "metadata": [
3
+ [
4
+ [
5
+ 0,
6
+ 12
7
+ ]
8
+ ]
9
+ ],
10
+ "name": [],
11
+ "description": [],
12
+ "resourceGroups": [
13
+ {
14
+ "name": [
15
+ [
16
+ 12,
17
+ 18
18
+ ]
19
+ ],
20
+ "description": [],
21
+ "resources": [
22
+ {
23
+ "name": [
24
+ [
25
+ 30,
26
+ 28
27
+ ]
28
+ ],
29
+ "description": [],
30
+ "uriTemplate": [
31
+ [
32
+ 30,
33
+ 28
34
+ ]
35
+ ],
36
+ "model": {},
37
+ "parameters": [
38
+ {
39
+ "name": [
40
+ [
41
+ 77,
42
+ 23
43
+ ]
44
+ ],
45
+ "description": [
46
+ [
47
+ 77,
48
+ 23
49
+ ]
50
+ ],
51
+ "type": [],
52
+ "required": [],
53
+ "default": [],
54
+ "example": [],
55
+ "values": [
56
+ [
57
+ [
58
+ 129,
59
+ 6
60
+ ]
61
+ ],
62
+ [
63
+ [
64
+ 147,
65
+ 6
66
+ ]
67
+ ],
68
+ [
69
+ [
70
+ 165,
71
+ 6
72
+ ]
73
+ ]
74
+ ]
75
+ }
76
+ ],
77
+ "actions": [
78
+ {
79
+ "name": [
80
+ [
81
+ 172,
82
+ 26
83
+ ]
84
+ ],
85
+ "description": [],
86
+ "method": [
87
+ [
88
+ 172,
89
+ 26
90
+ ]
91
+ ],
92
+ "parameters": [],
93
+ "examples": [
94
+ {
95
+ "name": [],
96
+ "description": [],
97
+ "requests": [],
98
+ "responses": [
99
+ {
100
+ "name": [
101
+ [
102
+ 200,
103
+ 27
104
+ ]
105
+ ],
106
+ "description": [],
107
+ "headers": [
108
+ [
109
+ [
110
+ 200,
111
+ 27
112
+ ]
113
+ ]
114
+ ],
115
+ "body": [
116
+ [
117
+ 231,
118
+ 17
119
+ ]
120
+ ],
121
+ "schema": []
122
+ }
123
+ ]
124
+ }
125
+ ]
126
+ },
127
+ {
128
+ "name": [
129
+ [
130
+ 249,
131
+ 27
132
+ ]
133
+ ],
134
+ "description": [],
135
+ "method": [
136
+ [
137
+ 249,
138
+ 27
139
+ ]
140
+ ],
141
+ "parameters": [],
142
+ "examples": [
143
+ {
144
+ "name": [],
145
+ "description": [],
146
+ "requests": [],
147
+ "responses": [
148
+ {
149
+ "name": [
150
+ [
151
+ 278,
152
+ 13
153
+ ]
154
+ ],
155
+ "description": [],
156
+ "headers": [],
157
+ "body": [],
158
+ "schema": []
159
+ }
160
+ ]
161
+ }
162
+ ]
163
+ }
164
+ ]
165
+ }
166
+ ]
167
+ }
168
+ ]
169
+ }
@@ -5,20 +5,36 @@ class RedSnowBindingTest < Test::Unit::TestCase
5
5
  context "RedSnow Binding" do
6
6
  should "convert API Blueprint to AST" do
7
7
 
8
- blueprint = FFI::MemoryPointer.new :pointer
9
8
  report = FFI::MemoryPointer.new :pointer
9
+ blueprint = FFI::MemoryPointer.new :pointer
10
+ sourcemap = FFI::MemoryPointer.new :pointer
10
11
 
11
- ret = RedSnow::Binding.sc_c_parse("meta: data\nfoo:bar\n#XXXX\ndescription for it", 0, report, blueprint)
12
+ ret = RedSnow::Binding.sc_c_parse("meta: data\nfoo:bar\n#XXXX\ndescription for it", 4, report, blueprint, sourcemap)
12
13
 
13
14
  blueprint = blueprint.get_pointer(0)
14
15
  report = report.get_pointer(0)
16
+ sourcemap = sourcemap.get_pointer(0)
17
+
15
18
  assert_equal "XXXX", RedSnow::Binding.sc_blueprint_name(blueprint)
16
19
 
20
+ sm_bluperint_name = RedSnow::Binding.sc_sm_blueprint_name(sourcemap)
21
+ assert_equal 1, RedSnow::Binding.sc_source_map_size(sm_bluperint_name)
22
+ assert_equal 19, RedSnow::Binding.sc_source_map_location(sm_bluperint_name, 0)
23
+ assert_equal 6, RedSnow::Binding.sc_source_map_length(sm_bluperint_name, 0)
24
+
17
25
  assert_equal "description for it", RedSnow::Binding.sc_blueprint_description(blueprint)
18
26
 
27
+ sm_bluperint_description = RedSnow::Binding.sc_sm_blueprint_description(sourcemap)
28
+ assert_equal 1, RedSnow::Binding.sc_source_map_size(sm_bluperint_description)
29
+ assert_equal 25, RedSnow::Binding.sc_source_map_location(sm_bluperint_description, 0)
30
+ assert_equal 18, RedSnow::Binding.sc_source_map_length(sm_bluperint_description, 0)
31
+
19
32
  meta_data_col = RedSnow::Binding.sc_metadata_collection_handle(blueprint)
20
33
  assert_equal 2, RedSnow::Binding.sc_metadata_collection_size(meta_data_col)
21
34
 
35
+ sm_meta_data_col = RedSnow::Binding.sc_sm_metadata_collection_handle(sourcemap)
36
+ assert_equal 2, RedSnow::Binding.sc_sm_metadata_collection_size(sm_meta_data_col)
37
+
22
38
  warnings = RedSnow::Binding.sc_warnings_handler(report)
23
39
  assert_equal 0, RedSnow::Binding.sc_warnings_size(warnings)
24
40
 
@@ -28,6 +44,7 @@ class RedSnowBindingTest < Test::Unit::TestCase
28
44
  assert_equal 0, RedSnow::Binding.sc_error_ok(error)
29
45
 
30
46
  RedSnow::Binding.sc_blueprint_free(blueprint)
47
+ RedSnow::Binding.sc_sm_blueprint_free(sourcemap)
31
48
  RedSnow::Binding.sc_report_free(report)
32
49
 
33
50
  end
@@ -0,0 +1,42 @@
1
+ require '_helper'
2
+
3
+ class RedSnowOptionsTest < Test::Unit::TestCase
4
+
5
+ context "Test arguments" do
6
+
7
+ context "Arguments" do
8
+ should "raise error if first parameter isn't String" do
9
+ exception = assert_raise(ArgumentError) {RedSnow.parse(1)}
10
+ assert_equal("Expected string value", exception.message)
11
+ end
12
+
13
+ should "get option for sourcemaps" do
14
+ options = RedSnow.parse_options({ :exportSourcemap => true })
15
+ assert_equal 4, options
16
+ end
17
+
18
+ should "get option for required Blueprint name" do
19
+ options = RedSnow.parse_options({ :requireBlueprintName => true })
20
+ assert_equal 2, options
21
+ end
22
+
23
+ should "get option for required Blueprint name and sourcemaps" do
24
+ options = RedSnow.parse_options({ :requireBlueprintName => true, :exportSourcemap => true })
25
+ assert_equal 6, options
26
+ end
27
+
28
+ should "get option for required Blueprint name and not sourcemaps" do
29
+ options = RedSnow.parse_options({ :requireBlueprintName => true, :exportSourcemap => false })
30
+ assert_equal 2, options
31
+ end
32
+
33
+ should "no options" do
34
+ options = RedSnow.parse_options(0)
35
+ assert_equal 0, options
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -24,7 +24,7 @@ class RedSnowParseResultTest < Test::Unit::TestCase
24
24
  # My API
25
25
  ## GET /
26
26
  STR
27
- @result = RedSnow.parse(@source.unindent)
27
+ @result = RedSnow.parse(@source.unindent, 4)
28
28
  end
29
29
 
30
30
  should "have name" do
@@ -35,6 +35,10 @@ class RedSnowParseResultTest < Test::Unit::TestCase
35
35
  assert_equal 0, @result.error[:code]
36
36
  end
37
37
 
38
+ should "have source map for api name" do
39
+ assert_equal [[11,9]], @result.sourcemap.name
40
+ end
41
+
38
42
  should "have some warning" do
39
43
  assert_equal RedSnow::WarningCodes::EmptyDefinitionWarning, @result.warnings[0][:code]
40
44
  assert_equal "action is missing a response", @result.warnings[0][:message]
data/test/redsnow_test.rb CHANGED
@@ -113,6 +113,7 @@ class RedSnowParsingTest < Test::Unit::TestCase
113
113
  @resourceGroup = @result.ast.resource_groups[0]
114
114
  @resource = @resourceGroup.resources[0]
115
115
  @action = @resource.actions[0]
116
+ @response = @resource.actions[1].examples[0].responses[0]
116
117
  end
117
118
 
118
119
  should "have resource group" do
@@ -145,6 +146,10 @@ class RedSnowParsingTest < Test::Unit::TestCase
145
146
  assert_equal "Method description\n\n", @action.description
146
147
  end
147
148
 
149
+ should "have reference" do
150
+ assert_equal "My Resource", @response.reference.id
151
+ end
152
+
148
153
  end
149
154
 
150
155
  context "parses blueprint metadata" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redsnow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ladislav Prskavec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -155,6 +155,7 @@ files:
155
155
  - ext/snowcrash/build/out/Release/obj.target/libmarkdownparser/ext/markdown-parser/src/MarkdownNode.o
156
156
  - ext/snowcrash/build/out/Release/obj.target/libmarkdownparser/ext/markdown-parser/src/MarkdownParser.o
157
157
  - ext/snowcrash/build/out/Release/obj.target/libsnowcrash/src/CBlueprint.o
158
+ - ext/snowcrash/build/out/Release/obj.target/libsnowcrash/src/CBlueprintSourcemap.o
158
159
  - ext/snowcrash/build/out/Release/obj.target/libsnowcrash/src/CSourceAnnotation.o
159
160
  - ext/snowcrash/build/out/Release/obj.target/libsnowcrash/src/HTTP.o
160
161
  - ext/snowcrash/build/out/Release/obj.target/libsnowcrash/src/MarkdownBlock.o
@@ -238,9 +239,12 @@ files:
238
239
  - ext/snowcrash/src/AssetParser.h
239
240
  - ext/snowcrash/src/Blueprint.h
240
241
  - ext/snowcrash/src/BlueprintParser.h
242
+ - ext/snowcrash/src/BlueprintSourcemap.h
241
243
  - ext/snowcrash/src/BlueprintUtility.h
242
244
  - ext/snowcrash/src/CBlueprint.cc
243
245
  - ext/snowcrash/src/CBlueprint.h
246
+ - ext/snowcrash/src/CBlueprintSourcemap.cc
247
+ - ext/snowcrash/src/CBlueprintSourcemap.h
244
248
  - ext/snowcrash/src/CSourceAnnotation.cc
245
249
  - ext/snowcrash/src/CSourceAnnotation.h
246
250
  - ext/snowcrash/src/CodeBlockUtility.h
@@ -348,13 +352,16 @@ files:
348
352
  - lib/redsnow/blueprint.rb
349
353
  - lib/redsnow/object.rb
350
354
  - lib/redsnow/parseresult.rb
355
+ - lib/redsnow/sourcemap.rb
351
356
  - lib/redsnow/version.rb
352
357
  - provisioning.sh
353
358
  - redsnow.gemspec
354
359
  - test/_helper.rb
355
360
  - test/fixtures/sample-api-ast.json
361
+ - test/fixtures/sample-api-sourcemap.json
356
362
  - test/fixtures/sample-api.apib
357
363
  - test/redsnow_binding_test.rb
364
+ - test/redsnow_options_test.rb
358
365
  - test/redsnow_parseresult_test.rb
359
366
  - test/redsnow_test.rb
360
367
  homepage: https://github.com/apiaryio/redsnow
@@ -385,8 +392,10 @@ summary: Ruby bindings for Snow Crash
385
392
  test_files:
386
393
  - test/_helper.rb
387
394
  - test/fixtures/sample-api-ast.json
395
+ - test/fixtures/sample-api-sourcemap.json
388
396
  - test/fixtures/sample-api.apib
389
397
  - test/redsnow_binding_test.rb
398
+ - test/redsnow_options_test.rb
390
399
  - test/redsnow_parseresult_test.rb
391
400
  - test/redsnow_test.rb
392
401
  has_rdoc: