public void DictArray() { Parser p = new Parser(StringToStream("<</1 [/Example (de) 3.14 null]>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["1"]; Assert.NotNull(entry); Assert.True(entry is ParseArray); ParseArray o = entry as ParseArray; Assert.NotNull(o); Assert.True(o.Objects.Count == 4); Assert.True(o.Objects[0] is ParseName); Assert.True((o.Objects[0] as ParseName).Value == "Example"); Assert.True(o.Objects[1] is ParseString); Assert.True((o.Objects[1] as ParseString).Value == "de"); Assert.True(o.Objects[2] is ParseReal); Assert.True((o.Objects[2] as ParseReal).Value == 3.14f); Assert.True(o.Objects[3] is ParseNull); }
public void DictMultipleCompact() { Parser p = new Parser(StringToStream("<</1/Example/2(de)/3 3.14/4 null>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 4); ParseObjectBase entry = d["1"]; Assert.NotNull(entry); Assert.True(entry is ParseName); Assert.True((entry as ParseName).Value == "Example"); entry = d["2"]; Assert.NotNull(entry); Assert.True(entry is ParseString); Assert.True((entry as ParseString).Value == "de"); entry = d["3"]; Assert.NotNull(entry); Assert.True(entry is ParseReal); Assert.True((entry as ParseReal).Value == 3.14f); entry = d["4"]; Assert.NotNull(entry); Assert.True(entry is ParseNull); }
public void CanTokensize() { using var file = File.OpenRead(@"Data\ZORK1.DAT"); var logger = NullLoggerFactory.GetLogger(); var machine = new Machine(logger, new SolveZorkInputStream()); machine.Load(file); var textBytes = new byte[37]; textBytes[0] = (byte)textBytes.Length; var textMemory = new MemoryLocation(1, textBytes.AsMemory()); var textBuffer = new TextBuffer(textMemory); textBuffer.Write("fred,go fishing"); var dictionary = new ParseDictionary(machine); textBuffer.Tokenize(dictionary); Assert.Equal(4, textBuffer.Tokens.Count); Assert.Equal("fred", textBuffer.Tokens[1]); Assert.Equal(",", textBuffer.Tokens[5]); Assert.Equal("go", textBuffer.Tokens[6]); Assert.Equal("fishing", textBuffer.Tokens[9]); }
public void DictInDict2() { Parser p = new Parser(StringToStream("<</1 <</A (de)>> /2 <</B (fg)>>>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 2); ParseObjectBase entry = d["1"]; Assert.NotNull(entry); Assert.True(entry is ParseDictionary); ParseDictionary d1 = entry as ParseDictionary; Assert.True(d1.Count == 1); entry = d1["A"]; Assert.NotNull(entry); Assert.True(entry is ParseString); Assert.True((entry as ParseString).Value == "de"); entry = d["2"]; Assert.NotNull(entry); Assert.True(entry is ParseDictionary); ParseDictionary d2 = entry as ParseDictionary; Assert.True(d2.Count == 1); entry = d2["B"]; Assert.NotNull(entry); Assert.True(entry is ParseString); Assert.True((entry as ParseString).Value == "fg"); }
public void DictEmpty() { Parser p = new Parser(StringToStream("<<>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 0); }
public void Trailer() { Parser p = new Parser(StringToStream("trailer\n<</Size 23/Root 1 0 R/Info 9 0 R/ID[<874BE86964CFD342BA4C701C72F4EB9F><874BE86964CFD342BA4C701C72F4EB9F>] >>\nstartxref")); ParseDictionary d = p.ParseTrailer(); Assert.NotNull(d); Assert.True(d.Count == 4); Assert.True(d["Size"] is ParseInteger); Assert.True(d["Root"] is ParseObjectReference); Assert.True(d["Info"] is ParseObjectReference); Assert.True(d["ID"] is ParseArray); }
public void DictNull() { Parser p = new Parser(StringToStream("<</Example null>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["Example"]; Assert.NotNull(entry); Assert.True(entry is ParseNull); }
public void CanDecodeDictionary() { using var file = File.OpenRead(@"Data\ZORK1.DAT"); var logger = NullLoggerFactory.GetLogger(); var machine = new Machine(logger, new SolveZorkInputStream()); machine.Load(file); var dictionary = new ParseDictionary(machine); Assert.Equal(0x2B9, dictionary.Words.Count); Assert.True(dictionary.Words.ContainsKey("altar")); Assert.False(dictionary.Words.ContainsKey("ackack")); }
public void DictName2() { Parser p = new Parser(StringToStream("<</Example/Other>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["Example"]; Assert.NotNull(entry); Assert.True(entry is ParseName); Assert.True((entry as ParseName).Value == "Other"); }
public void DictNumericInteger() { Parser p = new Parser(StringToStream("<</Example 42>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["Example"]; Assert.NotNull(entry); Assert.True(entry is ParseInteger); Assert.True((entry as ParseInteger).Value == 42); }
public void DictNumericReal() { Parser p = new Parser(StringToStream("<</Example 3.14>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["Example"]; Assert.NotNull(entry); Assert.True(entry is ParseReal); Assert.True((entry as ParseReal).Value == 3.14f); }
public void DictStringHex() { Parser p = new Parser(StringToStream("<</Example <6465>>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["Example"]; Assert.NotNull(entry); Assert.True(entry is ParseString); Assert.True((entry as ParseString).Value == "de"); }
public void DictBooleanTrue() { Parser p = new Parser(StringToStream("<</Example true>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["Example"]; Assert.NotNull(entry); Assert.True(entry is ParseBoolean); Assert.True((entry as ParseBoolean).Value); }
public void DictObjectReference1() { Parser p = new Parser(StringToStream("<</Example 99 1 R>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["Example"]; Assert.NotNull(entry); Assert.True(entry is ParseObjectReference); Assert.True((entry as ParseObjectReference).Id == 99); Assert.True((entry as ParseObjectReference).Gen == 1); }
public void Dict() { Parser p = new Parser(StringToStream("1 0 obj\n<</Type (Example)>>\nendobj")); ParseIndirectObject i = p.ParseIndirectObject() as ParseIndirectObject; Assert.NotNull(i); Assert.True(i.Id == 1); Assert.True(i.Gen == 0); Assert.NotNull(i.Object); ParseDictionary o = i.Object as ParseDictionary; Assert.NotNull(o); Assert.True(o.Count == 1); Assert.True(o["Type"] is ParseString); Assert.True((o["Type"] as ParseString).Value == "Example"); }
public void ArrayDict() { Parser p = new Parser(StringToStream("[<</Example (de)>>]")); ParseArray o = p.ParseObject() as ParseArray; Assert.NotNull(o); Assert.True(o.Objects.Count == 1); Assert.True(o.Objects[0] is ParseDictionary); ParseDictionary d = o.Objects[0] as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase obj = d["Example"]; Assert.NotNull(obj); Assert.True(obj is ParseString); Assert.True((obj as ParseString).Value == "de"); }
public void DictInDict1() { Parser p = new Parser(StringToStream("<</1 <</1 (de)>>>>")); ParseDictionary d = p.ParseObject() as ParseDictionary; Assert.NotNull(d); Assert.True(d.Count == 1); ParseObjectBase entry = d["1"]; Assert.NotNull(entry); Assert.True(entry is ParseDictionary); d = entry as ParseDictionary; Assert.True(d.Count == 1); entry = d["1"]; Assert.NotNull(entry); Assert.True(entry is ParseString); Assert.True((entry as ParseString).Value == "de"); }
public void CanPopulateParseBuffer() { using var file = File.OpenRead(@"Data\ZORK1.DAT"); var logger = NullLoggerFactory.GetLogger(); var machine = new Machine(logger, new SolveZorkInputStream()); machine.Load(file); var textBytes = new byte[37]; textBytes[0] = (byte)textBytes.Length; var textMemory = new MemoryLocation(1, textBytes.AsMemory()); var textBuffer = new TextBuffer(textMemory); textBuffer.Write("open mailbox"); var dictionary = new ParseDictionary(machine); textBuffer.Tokenize(dictionary); var parseBytes = new byte[128]; parseBytes[0] = (byte)parseBytes.Length; var parseMemory = new MemoryLocation(1, parseBytes.AsMemory()); var parseBuffer = new ParseBuffer(parseMemory); parseBuffer.Populate(textBuffer, dictionary); Assert.Equal(2, parseBytes[0]); Assert.Equal(0x46, parseBytes[1]); Assert.Equal(0x88, parseBytes[2]); Assert.Equal(0x04, parseBytes[3]); Assert.Equal(0x01, parseBytes[4]); }