diff --git a/spec/fixtures/basic.glug b/spec/fixtures/basic.glug new file mode 100644 index 0000000..983b8e0 --- /dev/null +++ b/spec/fixtures/basic.glug @@ -0,0 +1,13 @@ +version 8 +name 'My first stylesheet' +source :shortbread, type: 'vector', url: 'https://vector.openstreetmap.org/shortbread_v1/tilejson.json' + +layer(:roads, zoom: 10..13, source: :shortbread) do + line_width 6 + line_color match(highway, + 'motorway', :blue, + 'trunk', :green, + 'primary', :red, + 'secondary', :orange, + 0x888888) +end diff --git a/spec/fixtures/basic.json b/spec/fixtures/basic.json new file mode 100644 index 0000000..b70b9fe --- /dev/null +++ b/spec/fixtures/basic.json @@ -0,0 +1,36 @@ +{ + "version":8, + "name":"My first stylesheet", + "sources":{ + "shortbread":{ + "type":"vector", + "url":"https://vector.openstreetmap.org/shortbread_v1/tilejson.json" + } + }, + "layers":[ + { + "paint":{ + "line-width":6, + "line-color":[ + "match", + ["get","highway"], + "motorway", + "blue", + "trunk", + "green", + "primary", + "red", + "secondary", + "orange", + 8947848 + ] + }, + "source":"shortbread", + "id":"roads", + "source-layer":"roads", + "type":"line", + "minzoom":10, + "maxzoom":13 + } + ] +} diff --git a/spec/fixtures/basic_with_include.glug b/spec/fixtures/basic_with_include.glug new file mode 100644 index 0000000..057ab79 --- /dev/null +++ b/spec/fixtures/basic_with_include.glug @@ -0,0 +1,5 @@ +version 8 +name 'My first stylesheet' +source :shortbread, type: 'vector', url: 'https://vector.openstreetmap.org/shortbread_v1/tilejson.json' + +include_file('basic_with_include_sub.glug') diff --git a/spec/fixtures/basic_with_include.json b/spec/fixtures/basic_with_include.json new file mode 100644 index 0000000..b70b9fe --- /dev/null +++ b/spec/fixtures/basic_with_include.json @@ -0,0 +1,36 @@ +{ + "version":8, + "name":"My first stylesheet", + "sources":{ + "shortbread":{ + "type":"vector", + "url":"https://vector.openstreetmap.org/shortbread_v1/tilejson.json" + } + }, + "layers":[ + { + "paint":{ + "line-width":6, + "line-color":[ + "match", + ["get","highway"], + "motorway", + "blue", + "trunk", + "green", + "primary", + "red", + "secondary", + "orange", + 8947848 + ] + }, + "source":"shortbread", + "id":"roads", + "source-layer":"roads", + "type":"line", + "minzoom":10, + "maxzoom":13 + } + ] +} diff --git a/spec/fixtures/basic_with_include_sub.glug b/spec/fixtures/basic_with_include_sub.glug new file mode 100644 index 0000000..4132843 --- /dev/null +++ b/spec/fixtures/basic_with_include_sub.glug @@ -0,0 +1,9 @@ +layer(:roads, zoom: 10..13, source: :shortbread) do + line_width 6 + line_color match(highway, + 'motorway', :blue, + 'trunk', :green, + 'primary', :red, + 'secondary', :orange, + 0x888888) +end diff --git a/spec/lib/glug/stylesheet_spec.rb b/spec/lib/glug/stylesheet_spec.rb index 18e7a73..c3654fc 100644 --- a/spec/lib/glug/stylesheet_spec.rb +++ b/spec/lib/glug/stylesheet_spec.rb @@ -65,4 +65,26 @@ DOC .strip) end + + context 'with fixtures' do + let!(:fixture_dir) { File.join(File.dirname(__FILE__), '../../fixtures/') } + + it 'reads a basic file' do + glug = File.read(File.join(fixture_dir, 'basic.glug')) + stylesheet = described_class.new(base_dir: fixture_dir) do + instance_eval(glug) + end + output = File.read(File.join(fixture_dir, 'basic.json')) + expect(stylesheet.to_json).to eql(output.strip) + end + + it 'handles include_file method calls' do + glug = File.read(File.join(fixture_dir, 'basic_with_include.glug')) + stylesheet = described_class.new(base_dir: fixture_dir) do + instance_eval(glug) + end + output = File.read(File.join(fixture_dir, 'basic_with_include.json')) + expect(stylesheet.to_json).to eql(output.strip) + end + end end