Skip to content

Commit

Permalink
Fix compatibility with --frozen-string-literal
Browse files Browse the repository at this point in the history
  • Loading branch information
chaadow committed Jun 10, 2024
1 parent c5987d5 commit e322517
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ jobs:
matrix:
ruby: [ '3.1', '3.2', '3.3', 'head' ]
rails: [ '7.1', 'edge' ]
rubyopt: [""]
include:
- ruby: '2.7'
rails: '6.1'
- ruby: '3.0'
rails: '6.1'
- ruby: '3.1'
rails: '7.0'
- ruby: '3.3'
rails: ['edge', '7.1']
rubyopt: "--enable-frozen-string-literal"

env:
RAILS_VERSION: ${{ matrix.rails }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -29,10 +31,10 @@ jobs:
bundler-cache: true

- name: Run unit tests
run: bundle exec rake test:unit
run: bundle exec rake test:unit RUBYOPT="${{ matrix.rubyopt }}"
timeout-minutes: 3

- name: Run acceptance tests
run: bundle exec rake test:acceptance
run: bundle exec rake test:acceptance RUBYOPT="${{ matrix.rubyopt }}"
timeout-minutes: 10
if: ${{ matrix.rails != 'edge' && matrix.ruby != 'head' }} # Acceptance tests use `gem install rails && rails new`
3 changes: 1 addition & 2 deletions lib/spring/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
module Spring
module JSON
def self.load(string)
string.force_encoding("utf-8")
OkJson.decode(string)
end

Expand Down Expand Up @@ -364,7 +363,7 @@ def unquote(q)
end
end
if rubydoesenc?
a[w] = '' << uchar
a[w] = +'' << uchar
w += 1
else
w += ucharenc(a, w, uchar)
Expand Down
2 changes: 1 addition & 1 deletion test/support/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def read_streams
end

def read_stream(stream)
output = ""
output = +""
while IO.select([stream], [], [], 0.5) && !stream.eof?
output << stream.readpartial(10240)
end
Expand Down
12 changes: 12 additions & 0 deletions test/unit/json_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require_relative "../helper"
require 'spring/json'

class JsonTest < ActiveSupport::TestCase
test 'can decode unicode characters' do
assert_equal({"unicode_example"=>"©"}, Spring::JSON.load('{"unicode_example": "\u00A9"}'))
end

test 'can encode' do
assert_equal('{}', Spring::JSON.dump({}))
end
end

0 comments on commit e322517

Please sign in to comment.