4 |
import java |
import java |
5 |
import javax |
import javax |
6 |
|
|
7 |
|
######### |
8 |
|
# Helper classes |
9 |
|
|
10 |
class Ts(alph.TextSpan): |
class Ts(alph.TextSpan): |
11 |
def __init__(self, id, s, e): |
def __init__(self, sb, s, e): |
12 |
print "TS: ",id,s,e |
print "TS: ",sb,s,e |
13 |
self.id = id |
self.sb = sb |
14 |
self.s = s |
self.s = s |
15 |
self.e = e |
self.e = e |
16 |
|
def offset(self): |
17 |
|
return self.s |
18 |
|
def length(self): |
19 |
|
return self.e-self.s |
20 |
|
def getScrollBlock(self): |
21 |
|
return self.sb |
22 |
|
|
23 |
class Sb(alph.TextScrollBlock): |
class Sb(alph.TextScrollBlock): |
24 |
def __init__(self, id): |
def __init__(self, id): |
25 |
self.id = id |
self.id = id |
26 |
def getSpan(self, s, e): |
def getSpan(self, s, e): |
27 |
return Ts(self.id, s, e) |
return Ts(self, s, e) |
28 |
|
def getID(self): |
29 |
|
return self.id |
30 |
|
|
31 |
class Fact(SpanReader.ScrollBlockFactory): |
class Fact(SpanReader.ScrollBlockFactory): |
32 |
def getScrollBlock(self, id): |
def getScrollBlock(self, id): |
33 |
return Sb(id) |
return Sb(id) |
34 |
|
|
35 |
|
######### |
36 |
|
# Helper methods |
37 |
|
|
38 |
def getParser(): |
def getParser(): |
39 |
return javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser() |
return javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser() |
40 |
|
|
42 |
p = getParser() |
p = getParser() |
43 |
p.parse(java.io.StringBufferInputStream(string), handler) |
p.parse(java.io.StringBufferInputStream(string), handler) |
44 |
|
|
45 |
|
########### |
46 |
|
# Actual tests |
47 |
|
|
48 |
def testParseSpan(): |
def testParseSpan(): |
49 |
r = SpanReader() |
r = SpanReader() |
50 |
r.scrollBlockFactory = Fact() |
r.scrollBlockFactory = Fact() |
51 |
parseString("""<ts b="X" s="5" e="10"/>""", r) |
str = """<ts b="X" s="5" e="10"/>""" |
52 |
|
parseString(str, r) |
53 |
sp = r.getSpans()[0] |
sp = r.getSpans()[0] |
54 |
failUnlessEqual(sp.id, "X") |
failUnlessEqual(sp.sb.id, "X") |
55 |
failUnlessEqual(sp.s, 5) |
failUnlessEqual(sp.s, 5) |
56 |
failUnlessEqual(sp.e, 10) |
failUnlessEqual(sp.e, 10) |
57 |
|
|
58 |
|
failUnlessEqual(SpanSerializer().span2xml(sp), str) |