-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
152 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,21 @@ permissions: | |
contents: read | ||
|
||
jobs: | ||
Shared: | ||
uses: fog/.github/.github/workflows/[email protected] | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
ruby-version: ['3.0', '3.1', '3.2', '3.3', 'head'] | ||
continue-on-error: ${{ matrix.ruby-version == 'head' }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
- name: Run tests | ||
run: bundle exec rake RUBYOPT="--enable-frozen-string-literal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ def reset | |
end | ||
|
||
def characters(string) | ||
@value ||= '' | ||
@value ||= +'' | ||
@value << string | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
require 'minitest_helper' | ||
require 'fog/xml' | ||
|
||
# We expose accessors just for testing purposes | ||
Fog::ToHashDocument.attr_accessor(:value, :stack) | ||
|
||
describe Fog::ToHashDocument do | ||
before do | ||
@document = Fog::ToHashDocument.new | ||
end | ||
|
||
describe '#characters' do | ||
it 'appends characters to @value' do | ||
@document.characters("some text") | ||
_(@document.value).must_equal "some text" | ||
end | ||
|
||
it 'strips whitespace from characters' do | ||
@document.characters(" some text ") | ||
_(@document.value).must_equal "some text" | ||
end | ||
end | ||
|
||
describe '#end_element' do | ||
before do | ||
@document.stack << {} | ||
@document.characters("some text") | ||
end | ||
|
||
it 'adds element with text content to the stack' do | ||
@document.end_element('element') | ||
|
||
_(@document.stack.last).must_equal({ element: "some text" }) | ||
end | ||
|
||
it 'can mutate the new empty value' do | ||
@document.end_element('element') | ||
|
||
_(@document.value).must_equal("") | ||
|
||
# Mutate the new empty value even when frozen string literals are enabled | ||
_(@document.characters('one')) | ||
end | ||
|
||
it 'adds empty string if element is empty and value is empty' do | ||
@document.value = "" | ||
@document.end_element('element') | ||
_(@document.stack.last).must_equal({ element: "" }) | ||
end | ||
|
||
it 'adds nil if element has :i_nil attribute' do | ||
@document.stack.last[:i_nil] = "true" | ||
@document.value = "" | ||
|
||
@document.end_element('element') | ||
|
||
_(@document.stack.last).must_equal({ element: nil }) | ||
end | ||
end | ||
|
||
describe '#body' do | ||
it 'returns the first element of the stack' do | ||
@document.stack << { key: "value" } | ||
|
||
_(@document.body).must_equal({ key: "value" }) | ||
end | ||
end | ||
|
||
describe '#response' do | ||
it 'returns the body' do | ||
@document.stack << { key: "value" } | ||
|
||
_(@document.response).must_equal({ key: "value" }) | ||
end | ||
end | ||
|
||
describe '#start_element' do | ||
it 'parses attributes correctly' do | ||
@document.start_element('element', [['key', 'value']]) | ||
|
||
_(@document.stack.last).must_equal({ key: 'value' }) | ||
end | ||
|
||
it 'handles elements without attributes' do | ||
@document.start_element('element') | ||
|
||
_(@document.stack.last).must_equal({}) | ||
end | ||
|
||
it 'adds nested elements to the stack' do | ||
@document.start_element('parent') | ||
@document.start_element('child') | ||
|
||
_(@document.stack).must_equal([{:child=>{}}, {:child=>{}}, {}]) | ||
end | ||
|
||
it 'adds nested elements with attributes to the stack' do | ||
@document.start_element('parent') | ||
@document.start_element('child', [['key', 'value']]) | ||
|
||
_(@document.stack).must_equal([{:child=>{:key=>"value"}}, {:child=>{:key=>"value"}}, {:key=>"value"}] ) | ||
end | ||
|
||
it 'handles multiple children elements correctly' do | ||
@document.start_element('parent') | ||
@document.start_element('child1') | ||
@document.end_element('child1') | ||
@document.start_element('child2', [['key', 'value']]) | ||
@document.end_element('child2') | ||
|
||
_(@document.stack.first).must_equal({ | ||
child1: "", | ||
child2: { key: 'value' } | ||
}) | ||
end | ||
|
||
it 'handles text content within elements' do | ||
@document.start_element('parent') | ||
@document.characters('some text') | ||
@document.end_element('parent') | ||
|
||
_(@document.stack.first).must_equal({ parent: 'some text' }) | ||
end | ||
end | ||
end |