contrived_json 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ /* A Bison parser, made by GNU Bison 3.0.4. */
2
+
3
+ /* Bison interface for Yacc-like parsers in C
4
+
5
+ Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
+
20
+ /* As a special exception, you may create a larger work that contains
21
+ part or all of the Bison parser skeleton and distribute that work
22
+ under terms of your choice, so long as that work isn't itself a
23
+ parser generator using the skeleton or a modified version thereof
24
+ as a parser skeleton. Alternatively, if you modify or redistribute
25
+ the parser skeleton itself, you may (at your option) remove this
26
+ special exception, which will cause the skeleton and the resulting
27
+ Bison output files to be licensed under the GNU General Public
28
+ License without this special exception.
29
+
30
+ This special exception was added by the Free Software Foundation in
31
+ version 2.2 of Bison. */
32
+
33
+ #ifndef YY_YY_EXT_CONTRIVED_JSON_EXT_PARSER_PARSER_H_INCLUDED
34
+ # define YY_YY_EXT_CONTRIVED_JSON_EXT_PARSER_PARSER_H_INCLUDED
35
+ /* Debug traces. */
36
+ #ifndef YYDEBUG
37
+ # define YYDEBUG 0
38
+ #endif
39
+ #if YYDEBUG
40
+ extern int yydebug;
41
+ #endif
42
+
43
+ /* Token type. */
44
+ #ifndef YYTOKENTYPE
45
+ # define YYTOKENTYPE
46
+ enum yytokentype
47
+ {
48
+ TOK_EOF = 0,
49
+ TOK_TRUE = 258,
50
+ TOK_FALSE = 259,
51
+ TOK_NULL = 260,
52
+ TOK_STRING = 261,
53
+ TOK_NUMBER = 262,
54
+ TOK_UNKNOWN = 263
55
+ };
56
+ #endif
57
+
58
+ /* Value type. */
59
+ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
60
+ typedef VALUE YYSTYPE;
61
+ # define YYSTYPE_IS_TRIVIAL 1
62
+ # define YYSTYPE_IS_DECLARED 1
63
+ #endif
64
+
65
+ /* Location type. */
66
+ #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
67
+ typedef struct YYLTYPE YYLTYPE;
68
+ struct YYLTYPE
69
+ {
70
+ int first_line;
71
+ int first_column;
72
+ int last_line;
73
+ int last_column;
74
+ };
75
+ # define YYLTYPE_IS_DECLARED 1
76
+ # define YYLTYPE_IS_TRIVIAL 1
77
+ #endif
78
+
79
+
80
+
81
+ int yyparse (yyscan_t scanner, VALUE *object);
82
+
83
+ #endif /* !YY_YY_EXT_CONTRIVED_JSON_EXT_PARSER_PARSER_H_INCLUDED */
@@ -0,0 +1,3 @@
1
+ module ContrivedJSON
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1 @@
1
+ require 'contrived_json/ext_parser'
data/rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'rake/testtask'
2
+ require 'rake/extensiontask'
3
+
4
+
5
+ DIR_SRC = "ext/contrived_json/ext_parser"
6
+ DIR_ETC = "etc/contrived_json/ext_parser"
7
+
8
+ Rake::ExtensionTask.new do |ext|
9
+ ext.name = "ext_parser"
10
+ ext.ext_dir = DIR_SRC
11
+ ext.lib_dir = "lib/contrived_json"
12
+ end
13
+
14
+ Rake::TestTask.new do |t|
15
+ t.name = :test
16
+ t.libs << "lib"
17
+ t.test_files = FileList["test/**/tc_*.rb"]
18
+ end
19
+
20
+ task :flexbison do
21
+ system "flex --outfile=#{DIR_SRC}/lexer.c --header-file=#{DIR_SRC}/lexer.h #{DIR_ETC}/parser.l"
22
+ system "bison -d #{DIR_ETC}/parser.y --output=#{DIR_SRC}/parser.c"
23
+ end
24
+
25
+ task :benchmark do
26
+ system "ruby -Ilib -- benchmark/parse.rb"
27
+ end
28
+
29
+ task :default => :test
30
+
@@ -0,0 +1,91 @@
1
+ require 'test/unit'
2
+ require 'contrived_json'
3
+
4
+ class TestJSON < Test::Unit::TestCase
5
+
6
+ include ContrivedJSON
7
+
8
+ def test_no_input
9
+ input = ''
10
+ assert_nil(JSON.parse(input))
11
+ end
12
+
13
+ def test_wrong_type
14
+ input = 42
15
+ assert_raise TypeError do
16
+ JSON.parse(input)
17
+ end
18
+ end
19
+
20
+ def test_empty_object
21
+ input = '{}'
22
+ expected = {}
23
+ assert_equal(expected, JSON.parse(input))
24
+ end
25
+
26
+ def test_empty_array
27
+ input = '[]'
28
+ expected = []
29
+ assert_equal(expected, JSON.parse(input))
30
+ end
31
+
32
+ def test_unexpected_end_open_brace
33
+ input = '{'
34
+ assert_raise ParseError do
35
+ JSON.parse(input)
36
+ end
37
+ end
38
+
39
+ def test_unexpected_end_key
40
+ input = '{ "key"'
41
+ assert_raise ParseError do
42
+ JSON.parse(input)
43
+ end
44
+ end
45
+
46
+ def test_unexpected_end_colon
47
+ input = '{ "key" :'
48
+ assert_raise ParseError do
49
+ JSON.parse(input)
50
+ end
51
+ end
52
+
53
+ def test_unexpected_end_value
54
+ input = '{ "key" : null'
55
+ assert_raise ParseError do
56
+ JSON.parse(input)
57
+ end
58
+ end
59
+
60
+ def test_hello_world
61
+ input = <<-eos
62
+ {
63
+ "hello" : "hello",
64
+ "world" : "world"
65
+ }
66
+ eos
67
+ expected = {
68
+ "hello" => "hello",
69
+ "world" => "world"
70
+ }
71
+ assert_equal(expected, JSON.parse(input))
72
+ end
73
+
74
+ def test_unknown_token
75
+ input = "{ !"
76
+ assert_raise ParseError do
77
+ JSON.parse(input)
78
+ end
79
+ end
80
+
81
+ def test_unicode_string
82
+ input = '{"test":"\u005C"}'
83
+ JSON.parse(input)
84
+ end
85
+
86
+ def test_escaped_characters
87
+ input = '{"test":"\"\\\/\b\f\n\r\t\u005C"}'
88
+ JSON.parse(input)
89
+ end
90
+
91
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contrived_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Harper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email: contact@cjh.id.au
57
+ executables: []
58
+ extensions:
59
+ - ext/contrived_json/ext_parser/extconf.rb
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ext/contrived_json/ext_parser/extconf.rb
63
+ - ext/contrived_json/ext_parser/lexer.c
64
+ - ext/contrived_json/ext_parser/lexer.h
65
+ - ext/contrived_json/ext_parser/parser.c
66
+ - ext/contrived_json/ext_parser/parser.h
67
+ - lib/contrived_json.rb
68
+ - lib/contrived_json/version.rb
69
+ - rakefile
70
+ - test/tc_json_parse.rb
71
+ homepage: https://github.com/cjhdev/contrived_json
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.9.3
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.8
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A Flex/Bison based JSON parser
95
+ test_files:
96
+ - test/tc_json_parse.rb