Skip to content

Commit

Permalink
Add truffleruby support (#10)
Browse files Browse the repository at this point in the history
* add truffleruby support

* bump version

* fix tests
  • Loading branch information
foxtacles authored Jul 16, 2021
1 parent 6cc51e4 commit 069ec77
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
ruby-version: [2.5.x, 2.6.x, 2.7.x]
ruby: [2.5, 2.6, 2.7, truffleruby]

steps:
- uses: actions/checkout@v2
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: actions/setup-ruby@v1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Initialize submodules
uses: snickerbockers/submodules-init@v4
- name: Build and test with Rake
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PATH
remote: .
specs:
rj_schema (1.0.0)
rj_schema (1.0.1)

GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
benchmark-ips (2.7.2)
ecma-re-validator (0.2.0)
Expand All @@ -21,7 +21,7 @@ GEM
regexp_parser (~> 1.5)
uri_template (~> 0.7)
minitest (5.10.2)
public_suffix (4.0.3)
public_suffix (4.0.6)
rake (13.0.1)
rake-compiler (1.1.0)
rake
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Some limitations apply due to RapidJSON:

- only JSON schema draft-04 is supported
- the `format` keyword is not supported
- there are a few edge cases with regards to `$ref` that will cause issues (for more details, see the tests)

# Benchmark
The main motivation for this gem was that we needed a faster JSON schema validation for our Ruby apps. We have been using Ruby JSON Schema Validator for a while (https://github.com/ruby-json-schema/json-schema) but some of our endpoints became unacceptably slow.

Expand Down
2 changes: 1 addition & 1 deletion ext/rj_schema/rj_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <ruby.h>
#include <ruby/version.h>

#if (RUBY_API_VERSION_MAJOR > 2 || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR >= 7)) && defined(__GLIBC__)
#if (RUBY_API_VERSION_MAJOR > 2 || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR >= 7)) && defined(__GLIBC__) && !defined(TRUFFLERUBY)
namespace std {
static inline void* ruby_nonempty_memcpy(void *dest, const void *src, size_t n) {
return ::ruby_nonempty_memcpy(dest, src, n);
Expand Down
2 changes: 1 addition & 1 deletion lib/rj_schema.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'json'

class RjSchema
VERSION = '1.0.0'
VERSION = '1.0.1'
end

require 'rj_schema/rj_schema'
2 changes: 1 addition & 1 deletion rj_schema.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Gem::Specification.new 'rj_schema', '1.0.0' do |s|
Gem::Specification.new 'rj_schema', '1.0.1' do |s|
s.licenses = %w[MIT]
s.summary = 'JSON schema validation with RapidJSON'
s.description = 'gem using RapidJSON as a backend to provide fast validation for JSON schemas'
Expand Down
5 changes: 2 additions & 3 deletions test/rj_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ class RjSchemaTest < Minitest::Test
full_description = "#{base_description}/#{t['description']}"

err_id = "#{rel_file}: #{full_description}"
locals["test_#{err_id}"] = schema unless rel_file.include?('/optional/') || err_id.include?("change resolution scope")
locals["test_#{err_id}"] = schema unless rel_file.include?('/optional/')
define_method("test_#{err_id}") do
skip('most notably, the "format" keyword is not implemented in RapidJSON') if rel_file.include? '/optional/'
skip('The failed test is "changed scope ref invalid" of "change resolution scope" in refRemote.json. It is due to that id schema keyword and URI combining function are not implemented.') if err_id.include? "change resolution scope"
skip('the "format" keyword is not implemented in RapidJSON') if rel_file.include? '/optional/'

errors = VALIDATOR.validate(schema, t["data"].to_json, continue_on_error: true, machine_errors: true, human_errors: true)
assert_equal t["valid"], errors[:machine_errors].empty?, "Common test suite case failed: #{err_id}"
Expand Down

0 comments on commit 069ec77

Please sign in to comment.