Skip to content

Commit 693eb66

Browse files
committed
Test JSON extraction
1 parent 6c6f67b commit 693eb66

2 files changed

Lines changed: 62 additions & 10 deletions

File tree

β€Žtest/jquery.microdata.htmlβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<script src="qunit/qunit/qunit.js"></script>
77
<link rel="stylesheet" href="qunit/qunit/qunit.css">
88
<script src="../lib/jquery-1.6.4.min.js"></script>
9+
<script src="../lib/json2.js"></script>
910
<script src="../jquery.microdata.js"></script>
11+
<script src="../jquery.microdata.json.js"></script>
1012
<style>#testdata{display:none;}</style>
1113
</head>
1214
<body>
@@ -30,20 +32,18 @@ <h2 id="qunit-userAgent"></h2>
3032
<div id="dupref" itemscope itemref="w1 w1"></div>
3133

3234
<div id="loops" itemscope>
33-
<div id="plain" itemprop="text">plain property</div>
3435
<div id="loop0" itemprop="self" itemscope itemref="loop0"></div>
3536
<div id="loop1" itemprop="head" itemscope itemref="loop2">not in the loop</div>
36-
<div id="loop2" itemprop="next" itemscope itemref="loop3"></div>
37-
<div id="loop3" itemprop="next" itemscope itemref="loop4"></div>
38-
<div id="loop4" itemprop="next" itemscope itemref="loop2"></div>
37+
<div id="loop2" itemprop="first" itemscope itemref="loop3"></div>
38+
<div id="loop3" itemprop="last" itemscope itemref="loop2"></div>
3939
</div>
4040

4141
<div id="io"> <!-- inside-out -->
42-
<div id="ioBefore" itemprop="oddstuff">included via parent</div>
42+
<div id="ioBefore" itemprop="oddstuff">via parent</div>
4343
<div id="ioItem" itemscope itemref="io">
44-
<div id="ioChild" itemprop="oddstuff">included via tree</div>
44+
<div id="ioChild" itemprop="oddstuff">via tree</div>
4545
</div>
46-
<div id="ioAfter" itemprop="oddstuff">included via parent</div>
46+
<div id="ioAfter" itemprop="oddstuff">via parent</div>
4747
</div>
4848
</div>
4949

β€Žtest/jquery.microdata.unit.jsβ€Ž

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ test('jQuery.fn.properties', function() {
3434
t('#x', 'work', ['x0']);
3535
t('#x', 'author', ['w2']);
3636
t('#dupref', undefined, ['w1']);
37-
t('#loops', undefined, ['plain', 'loop0','loop1', 'loop2', 'loop3', 'loop4']);
37+
t('#loops', undefined, ['loop0','loop1', 'loop2', 'loop3']);
3838
t('#loop0', undefined, []);
3939
t('#loop1', undefined, ['loop2']);
4040
t('#loop2', undefined, ['loop3']);
41-
t('#loop3', undefined, ['loop4']);
42-
t('#loop4', undefined, ['loop2']);
41+
t('#loop3', undefined, ['loop2']);
4342
t('#ioItem', undefined, ['ioBefore', 'ioChild', 'ioAfter']);
4443
t('#dupprops', undefined, ['foo0', 'bar0', 'bar1', 'foo1']);
4544
t('#dupprops', 'foo', ['foo0', 'foo1']);
@@ -176,3 +175,56 @@ test('time', function() {
176175
equal($('<time itemprop>now</time>').itemValue(), 'now');
177176
equal($('<time itemprop datetime="1984-09-03">then</time>').itemValue(), '1984-09-03');
178177
});
178+
179+
module('jQuery.microdata.json');
180+
181+
test('JSON extraction', function() {
182+
var json = $.microdata.json();
183+
deepEqual(JSON.parse(json), { items: [
184+
{
185+
type: ['http://n.whatwg.org/work'],
186+
properties: {
187+
work: ['http://foolip.org/microdatajs/'],
188+
title: ['MicrodataJS'],
189+
author: ['Philip JΓ€genstedt'],
190+
license: ['http://creativecommons.org/licenses/by/3.0/']
191+
}
192+
},
193+
{
194+
type: ['http://n.whatwg.org/work', 'http://n.foolip.org/work'],
195+
properties: {
196+
author: ['Philip JΓ€genstedt'],
197+
license: ['http://creativecommons.org/licenses/by/3.0/'],
198+
work: ['http://blog.foolip.org/'],
199+
title: ['Pretentious Nonsense']
200+
}
201+
},
202+
{
203+
properties: {
204+
title: ['MicrodataJS']
205+
}
206+
},
207+
{
208+
properties: {
209+
self: [ { properties: {} } ],
210+
head: [ { properties: { first: [ { properties: { last: [ { properties: { first: ['ERROR'] } } ] } } ] } } ],
211+
first: [ { properties: { last: [ { properties: { first: ['ERROR'] } } ] } } ],
212+
last: [ { properties: { first: [ { properties: { last: ['ERROR'] } } ] } } ]
213+
}
214+
},
215+
{
216+
properties: {
217+
oddstuff: ['via parent', 'via tree', 'via parent']
218+
}
219+
},
220+
{
221+
properties: {
222+
foo: ['', ''],
223+
bar: ['', '']
224+
}
225+
},
226+
{
227+
properties: {}
228+
}
229+
]});
230+
});

0 commit comments

Comments
 (0)