Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added test for rendering from tokens. removed unneccessary line from …

….npmignore
  • Loading branch information...
commit 47c77e1f39fa73c6aea393d0f507bf13b4a89222 1 parent 7868a66
@mreinstein mreinstein authored
View
2  .npmignore
@@ -1 +1 @@
-.DS_Store
+
View
80 fixtures/html5-doctor-tokens.json
@@ -0,0 +1,80 @@
+[
+ {
+ "type": "magic signature",
+ "value": "CACHE MANIFEST"
+ },
+ {
+ "type": "newline"
+ },
+ {
+ "type": "comment",
+ "value": " This is a comment"
+ },
+ {
+ "type": "newline"
+ },
+ {
+ "type": "mode",
+ "value": "CACHE"
+ },
+ {
+ "type": "data",
+ "tokens": [
+ "/css/screen.css"
+ ]
+ },
+ {
+ "type": "data",
+ "tokens": [
+ "/css/offline.css"
+ ]
+ },
+ {
+ "type": "data",
+ "tokens": [
+ "/js/screen.js"
+ ]
+ },
+ {
+ "type": "data",
+ "tokens": [
+ "/img/logo.png"
+ ]
+ },
+ {
+ "type": "newline"
+ },
+ {
+ "type": "data",
+ "tokens": [
+ "http://example.com/css/styles.css"
+ ]
+ },
+ {
+ "type": "newline"
+ },
+ {
+ "type": "mode",
+ "value": "FALLBACK"
+ },
+ {
+ "type": "data",
+ "tokens": [
+ "/",
+ "/offline.html"
+ ]
+ },
+ {
+ "type": "newline"
+ },
+ {
+ "type": "mode",
+ "value": "NETWORK"
+ },
+ {
+ "type": "data",
+ "tokens": [
+ "*"
+ ]
+ }
+]
View
17 fixtures/html5-doctor.appcache
@@ -0,0 +1,17 @@
+CACHE MANIFEST
+
+# This is a comment
+
+CACHE:
+/css/screen.css
+/css/offline.css
+/js/screen.js
+/img/logo.png
+
+http://example.com/css/styles.css
+
+FALLBACK:
+/ /offline.html
+
+NETWORK:
+*
View
2  lib/render-appcache-manifest.js
@@ -77,7 +77,7 @@
} else if (t.type === 'newline') {
out += '\n';
} else if (t.type === 'comment') {
- line = '# ' + t.value;
+ line = '# ' + t.value.trim();
} else if (t.type === 'mode' && t.value !== 'unknown') {
line = t.value + ':';
} else if (t.type === 'data') {
View
2  lib/render-appcache-manifest.map
@@ -6,5 +6,5 @@
"src/render-appcache-manifest.coffee"
],
"names": [],
- "mappings": ";AAAA;CAAA,KAAA,IAAA;;CAAA,CAAA,CAAiB,CAAA,EAAX,CAAN,EAAkB;CAChB,OAAA,wGAAA;CAAA,GAAA,CAAQ,EAAL;CAAyB,GAAO,MAAA,GAAA;MAAnC;AAEuB,CAAvB,GAAA,CAAA;CAAA,CAAA,CAAa,CAAT,CAAJ,CAAA;MAFA;AAGyB,CAAzB,GAAA,GAAA;CAAA,CAAA,CAAe,CAAX,EAAJ,CAAA;MAHA;AAI0B,CAA1B,GAAA,IAAA;CAAA,CAAA,CAAgB,CAAZ,EAAJ,EAAA;MAJA;AAK0B,CAA1B,GAAA,IAAA;CAAA,CAAA,CAAgB,CAAZ,EAAJ,EAAA;MALA;CAMA,GAAA,GAAA;CAAA,GAAI,EAAJ,CAAA,CAAa;MANb;CAAA,EAOc,CAAd,EAAc,EAAa,GAA3B,CAAc;CAPd,CAAA,CAQQ,CAAR,CAAA;CARA,GASA,CAAK,WAAL;CATA,CAUA,EAAA,CAAK;CACL;CAAA,QAAA,kCAAA;wBAAA;CAAA,GAAA,CAAK,CAAL;CAAA,IAXA;CAYA,EAAyB,CAAzB,EAAG,CAAY;CACb,CAAA,EAAA,CAAK,CAAL;CAAA,GACA,CAAK,CAAL,IAAA;CACA;CAAA,UAAA,mCAAA;2BAAA;CAAA,GAAA,CAAK,GAAL;CAAA,MAHF;MAZA;CAgBA,EAAuC,CAAvC,EAAS,EAAN;CACD,CAAA,EAAA,CAAK,CAAL;CAAA,GACA,CAAK,CAAL,KAAA;CACA;CAAA,UAAA,KAAA;mCAAA;CAAA,CAAW,CAAE,CAAb,CAAK,EAAM,CAAX;CAAA,MAHF;MAhBA;CAoBA,GAAA,EAAA,GAAiB;CAAjB,CAAA,EAAA,CAAK,CAAL;M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AAA;CAKE,EAAO,CAAP,CAAqB,GAArB;CACO,GAAD,CAAU,CANlB,EAAA,CAAA;CAOE,EAAO,CAAP,CAAO,GAAP;CACO,GAAD,CAAU,CARlB,EAAA;CASE,EAAO,CAAP,EAAe,EAAf;QAVF;CAWA,GAAG,EAAH;CACE,EAAA,CAAM,IAAN;QAbJ;CAAA,IADA;CAFW,UAiBX;CA7CF,EA4Ba;CA5Bb"
}
View
2  src/render-appcache-manifest.coffee
@@ -36,7 +36,7 @@ fromTokens = (tokens) ->
else if t.type is 'newline'
out += '\n'
else if t.type is 'comment'
- line = '# ' + t.value
+ line = '# ' + t.value.trim()
else if t.type is 'mode' and t.value isnt 'unknown'
line = t.value + ':'
else if t.type is 'data'
View
9 test/render-appcache-manifest.coffee
@@ -1,5 +1,7 @@
assert = require "assert"
render = require "../"
+fs = require "fs"
+path = require "path"
expected = """
CACHE MANIFEST
@@ -19,6 +21,7 @@ foo bar
fizz buzz
"""
+
describe "renderAppcacheManifest", ->
it "renders an appcache manifest", ->
assert.equal expected, render
@@ -27,6 +30,12 @@ describe "renderAppcacheManifest", ->
fallback:
foo: "bar"
fizz: "buzz"
+
+ it "renders an appcache manifest from tokens", ->
+ manifestPath = path.resolve(__dirname, "../fixtures/html5-doctor.appcache")
+ expect = fs.readFileSync manifestPath, 'utf8'
+ tokens = require "../fixtures/html5-doctor-tokens.json"
+ assert.equal expect, render(tokens)
it "renders a unique appcache manfiest", ->
actual = render
Please sign in to comment.
Something went wrong with that request. Please try again.