Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean scoping mechanism, keeping proper linear parent chains.
- Loading branch information
Showing
15 changed files
with
131 additions
and
79 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
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 was deleted.
Oops, something went wrong.
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,4 @@ | ||
--- | ||
who: world | ||
--- | ||
Hello ${who}! |
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,16 @@ | ||
require 'spec_helper' | ||
module WLang | ||
describe "WLang scoping rules" do | ||
|
||
let(:template){ Template.new(Path.dir / 'hello.wlang') } | ||
|
||
specify 'template locals are used by default' do | ||
template.render.should eq("Hello world!") | ||
end | ||
|
||
specify 'template locals are overriden by render locals' do | ||
template.render(:who => "wlang").should eq("Hello wlang!") | ||
end | ||
|
||
end | ||
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
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
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
require 'spec_helper' | ||
module WLang | ||
describe Scope, 'push' do | ||
|
||
let(:x_scope){ Scope.coerce(:x) } | ||
|
||
subject{ x_scope.push(pushed) } | ||
|
||
before do | ||
subject.should be_a(Scope) | ||
end | ||
|
||
after do | ||
x_scope.parent.should be_nil | ||
x_scope.subject.should eq(:x) | ||
x_scope.root.should eq(x_scope) | ||
end | ||
|
||
context 'when pushing a simple value' do | ||
let(:pushed){ :y } | ||
|
||
it 'returns the scope with correct subject' do | ||
subject.subject.should eq(:y) | ||
end | ||
|
||
it 'sets the parent correctly on created scope' do | ||
subject.parent.should eq(x_scope) | ||
end | ||
|
||
it 'returns the correct root scope' do | ||
subject.root.should eq(x_scope) | ||
end | ||
end | ||
|
||
context 'when pushing another scope' do | ||
let(:pushed){ Scope.coerce(:y).push(:z) } | ||
|
||
it 'returns the scope with most specific subject' do | ||
subject.subject.should eq(:z) | ||
end | ||
|
||
it 'rechains parents correctly' do | ||
subject.parent.subject.should eq(:y) | ||
subject.parent.parent.subject.should eq(:x) | ||
subject.parent.parent.parent.should be_nil | ||
end | ||
|
||
it 'returns the correct root scope' do | ||
subject.root.should eq(x_scope) | ||
end | ||
|
||
it 'does not touch the original scope' do | ||
pushed.subject.should eq(:z) | ||
pushed.parent.subject.should eq(:y) | ||
pushed.parent.parent.should be_nil | ||
pushed.root.should eq(pushed.parent) | ||
end | ||
end | ||
|
||
end | ||
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