Пример #1
0
		////////////////////////////////////////////////////////////////////////////
		// Tag Tests
		////////////////////////////////////////////////////////////////////////////
		private static void TestTag() {	
			Console.WriteLine("Doing basic Tag tests...");
			
			// Test to make sure Tag ignores the order in which attributes are
			// added.
			Console.WriteLine("    Making sure attributes are consistently ordered...");
			Tag t1 = new Tag("test");
			t1["foo"]="bar";
            t1["john"]="doe";
			
			Tag t2 = new Tag("test");
            t2["john"]="doe";
			t2["foo"]="bar";
			
			AssertEquals(TAG, t1, t2);
			
			Console.WriteLine("    Making sure tags with different structures return " +
					"false from .equals...");
			
			t2.Value="item";
			AssertNotEquals(TAG, t1, t2);
			
			t2.RemoveValue("item");
			t2["another"] = "attribute";
			AssertNotEquals(TAG, t1, t2);
			
			Console.WriteLine("    Checking attributes namespaces...");
			
			t2["name"]="bill";

            // setting attributes with namespaces
			t2["private","smoker"]=true;
			t2["public", "hobby"]="hiking";
			t2["private", "nickname"]="tubby";

			AssertEquals(TAG, t2.GetAttributesForNamespace("private"),
					Map("smoker",true,"nickname","tubby"));
		}	
Пример #2
0
		public static void TestValues(Tag root) {
			Console.WriteLine("Doing values tests...");
	
			AssertEquals(VALUES, root.GetChild("values1").Values, List("hi"));
			AssertEquals(VALUES, root.GetChild("values2").Values, List("hi","ho"));
			AssertEquals(VALUES, root.GetChild("values3").Values, List(1, "ho"));	
			AssertEquals(VALUES, root.GetChild("values4").Values, List("hi",5));
			AssertEquals(VALUES, root.GetChild("values5").Values, List(1,2));	
			AssertEquals(VALUES, root.GetChild("values6").Values, List(1,2,3));	
			AssertEquals(VALUES, root.GetChild("values7").Values,
					List(null,"foo",false,GetDate(1980,12,5)));		
			AssertEquals(VALUES, root.GetChild("values8").Values,
					List(null, "foo", false, GetDateTime(1980,12,5,12,30,0,0,null),
							"there", new TimeSpan(0,15,23,12,234)));
			AssertEquals(VALUES, root.GetChild("values9").Values,
					List(null, "foo", false, GetDateTime(1980,12,5,12,30,0,0,null),
							"there", GetDateTime(1989,8,12,15,23,12,234,"JST")));
			AssertEquals(VALUES, root.GetChild("values10").Values,
					List(null, "foo", false, GetDateTime(1980,12,5,12,30,0,0,null),
							"there", new TimeSpan(0,15,23,12,234), "more stuff"));
			AssertEquals(VALUES, root.GetChild("values11").Values,
					List(null, "foo", false, GetDateTime(1980,12,5,12,30,0,0,null),
							"there", new TimeSpan(123,15,23,12,234),
							"more stuff here"));		
			AssertEquals(VALUES, root.GetChild("values12").Values, List(1,3));
			AssertEquals(VALUES, root.GetChild("values13").Values, List(1,3));
			AssertEquals(VALUES, root.GetChild("values14").Values, List(1,3));	
			AssertEquals(VALUES, root.GetChild("values15").Values, List(1,2,4,5,6));
			AssertEquals(VALUES, root.GetChild("values16").Values, List(1,2,5));	
			AssertEquals(VALUES, root.GetChild("values17").Values, List(1,2,5));		
			AssertEquals(VALUES, root.GetChild("values18").Values, List(1,2,7));	
			AssertEquals(VALUES, root.GetChild("values19").Values,
					List(1,3,5,7));	
			AssertEquals(VALUES, root.GetChild("values20").Values,
					List(1,3,5));		
			AssertEquals(VALUES, root.GetChild("values21").Values,
					List(1,3,5));			 
			AssertEquals(VALUES, root.GetChild("values22").Values,
					List("hi","ho","ho",5,"hi"));			
		}
Пример #3
0
		////////////////////////////////////////////////////////////////////////////
		// Structure Tests (values, attributes, children)
		////////////////////////////////////////////////////////////////////////////
		
		public static void TestEmptyTag(Tag root) {
			Console.WriteLine("Doing empty tag test...");
			
			AssertEquals(EMPTY_TAG, root.GetChild("empty_tag"), new Tag("empty_tag"));
		}
Пример #4
0
 private void AddTagAttributes(Tag tag, IList<Token> toks, int tpos)
 {
     int index1 = tpos;
       for (int count = toks.Count; index1 < count; {
     int num;
     index1 = num + 1;
       }
       )
       {
     Token token1 = toks[index1];
     if (token1.type != Type.IDENTIFIER)
       this.ExpectingButGot("IDENTIFIER", (object) token1.type, token1.line, token1.position);
     string index2 = token1.text;
     if (index1 == count - 1)
       this.ExpectingButGot("\":\" or \"=\" \"LITERAL\"", (object) "END OF LINE.", token1.line, token1.position);
     Token token2 = toks[num = index1 + 1];
     if (token2.type == Type.COLON)
     {
       if (num == count - 1)
     this.ExpectingButGot("IDENTIFIER", (object) "END OF LINE", token2.line, token2.position);
       int num1;
       Token token3 = toks[num1 = num + 1];
       if (token3.type != Type.IDENTIFIER)
     this.ExpectingButGot("IDENTIFIER", (object) token3.type, token3.line, token3.position);
       string index3 = token3.text;
       if (num1 == count - 1)
     this.ExpectingButGot("\"=\"", (object) "END OF LINE", token3.line, token3.position);
       int num2;
       Token token4 = toks[num2 = num1 + 1];
       if (token4.type != Type.EQUALS)
     this.ExpectingButGot("\"=\"", (object) token4.type, token4.line, token4.position);
       if (num2 == count - 1)
     this.ExpectingButGot("LITERAL", (object) "END OF LINE", token4.line, token4.position);
       Token token5 = toks[num = num2 + 1];
       if (!token5.literal)
     this.ExpectingButGot("LITERAL", (object) token5.type, token5.line, token5.position);
       if (token5.type == Type.DATE && num + 1 < count && toks[num + 1].type == Type.TIME)
       {
     SDLDateTime dt = (SDLDateTime) token5.GetObjectForLiteral();
     TimeSpanWithZone tswz = (TimeSpanWithZone) toks[num + 1].GetObjectForLiteral();
     if (tswz.Days != 0)
       this.ExpectingButGot("TIME (component of date/time) in attribute value", (object) "TIME SPAN", token5.line, token5.position);
     tag[index2, index3] = (object) Parser.Combine(dt, tswz);
     ++num;
       }
       else
       {
     object objectForLiteral = token5.GetObjectForLiteral();
     if (objectForLiteral is TimeSpanWithZone)
     {
       TimeSpanWithZone timeSpanWithZone = (TimeSpanWithZone) objectForLiteral;
       if (timeSpanWithZone.TimeZone != null)
         this.ExpectingButGot("TIME SPAN", (object) "TIME (component of date/time)", token5.line, token5.position);
       TimeSpan timeSpan = new TimeSpan(timeSpanWithZone.Days, timeSpanWithZone.Hours, timeSpanWithZone.Minutes, timeSpanWithZone.Seconds, timeSpanWithZone.Milliseconds);
       tag[index2, index3] = (object) timeSpan;
     }
     else
       tag[index2, index3] = objectForLiteral;
       }
     }
     else if (token2.type == Type.EQUALS)
     {
       if (num == count - 1)
     this.ExpectingButGot("LITERAL", (object) "END OF LINE", token2.line, token2.position);
       Token token3 = toks[++num];
       if (!token3.literal)
     this.ExpectingButGot("LITERAL", (object) token3.type, token3.line, token3.position);
       if (token3.type == Type.DATE && num + 1 < count && toks[num + 1].type == Type.TIME)
       {
     SDLDateTime dt = (SDLDateTime) token3.GetObjectForLiteral();
     TimeSpanWithZone tswz = (TimeSpanWithZone) toks[num + 1].GetObjectForLiteral();
     if (tswz.Days != 0)
       this.ExpectingButGot("TIME (component of date/time) in attribute value", (object) "TIME SPAN", token3.line, token3.position);
     tag[index2] = (object) Parser.Combine(dt, tswz);
     ++num;
       }
       else
       {
     object objectForLiteral = token3.GetObjectForLiteral();
     if (objectForLiteral is TimeSpanWithZone)
     {
       TimeSpanWithZone timeSpanWithZone = (TimeSpanWithZone) objectForLiteral;
       if (timeSpanWithZone.TimeZone != null)
         this.ExpectingButGot("TIME SPAN", (object) "TIME (component of date/time)", token3.line, token3.position);
       TimeSpan timeSpan = new TimeSpan(timeSpanWithZone.Days, timeSpanWithZone.Hours, timeSpanWithZone.Minutes, timeSpanWithZone.Seconds, timeSpanWithZone.Milliseconds);
       tag[index2] = (object) timeSpan;
     }
     else
       tag[index2] = objectForLiteral;
       }
     }
     else
       this.ExpectingButGot("\":\" or \"=\"", (object) token2.type, token2.line, token2.position);
       }
 }
Пример #5
0
Файл: Tag.cs Проект: Zeludon/FEZ
 public void AddChild(Tag child)
 {
     this.childrenDirty = true;
       this.children.Add(child);
 }
Пример #6
0
		private static void TestStructures() {
			
			Console.WriteLine("Reading test_structures.sdl");
			
			Tag root = null;
			
			try {
				root=new Tag("root").ReadFile("test_structures.sdl");
			} catch(IOException ioe) {
				ReportException("Problem reading test_structures.sdl", ioe);
			} catch(SDLParseException spe) {
				ReportException("Problem parsing test_structures.sdl", spe);
			}
			
			Console.WriteLine("Successfully read and parsed test_structures.sdl");
	
			try { TestTagWriteParse("test_structures.sdl", root); } catch(Exception e) {
				ReportException(TAG_WRITE_PARSE, e);
			}		
			
			try { TestEmptyTag(root); } catch(Exception e) {
				ReportException(EMPTY_TAG, e);
			}		
			
			try { TestValues(root); } catch(Exception e) {
				ReportException(VALUES, e);
			}
			
			try { TestAttributes(root); } catch(Exception e) {
				ReportException(ATTRIBUTES, e);
			}
			
			try { TestValuesAndAttributes(root); } catch(Exception e) {
				ReportException(VALUES_AND_ATTRIBUTES, e);
			}	
			
			try { TestChildren(root); } catch(Exception e) {
				ReportException(CHILDREN, e);
			}	
			
			try { TestNamespaces(root); } catch(Exception e) {
				ReportException(NAMESPACES, e);
			}
		}
Пример #7
0
		private static void TestBasicTypes() {
			
			Console.WriteLine("Reading test_basic_types.sdl");
			
			Tag root = null;
			
			try {
				root=new Tag("root").ReadFile("test_basic_types.sdl");
			} catch(IOException ioe) {
				ReportException("Problem reading test_basic_types.sdl", ioe);
			} catch(SDLParseException spe) {
				ReportException("Problem parsing test_basic_types.sdl", spe);
			}
			
			Console.WriteLine("Successfully read and parsed test_basic_types.sdl");	
			
			try { TestTagWriteParse("test_basic_types.sdl", root); } catch(Exception e) {
				ReportException(TAG_WRITE_PARSE, e);
			}
			
			try { TestStrings(root); } catch(Exception e) {
				ReportException(STRING_DECLARATIONS, e);
			}
			
			try { TestCharacters(root); } catch(Exception e) {
				ReportException(CHARACTER_DECLARATIONS, e);
			}
			
			try { TestNumbers(root); } catch(Exception e) {
				ReportException(NUMBER_DECLARATIONS, e);
			}		
	
			try { TestBooleans(root); } catch(Exception e) {
				ReportException(BOOLEAN_DECLARATIONS, e);
			}
			
			try { TestNull(root); } catch(Exception e) {
				ReportException(NULL_DECLARATION, e);
			}
			
			try { TestDates(root); } catch(Exception e) {
				ReportException(DATE_DECLARATIONS, e);
			}
			
			try { TestTimeSpans(root); } catch(Exception e) {
				ReportException(TIME_SPAN_DECLARATIONS, e);
			}
			
			try { TestDateTimes(root); } catch(Exception e) {
				ReportException(DATE_TIME_DECLARATIONS, e);
			}
			
			try { TestBinaries(root); } catch(Exception e) {
				ReportException(BINARY_DECLARATIONS, e);
			}
		}
Пример #8
0
		public static void TestChildren(Tag root) {
			Console.WriteLine("Doing children tests...");
	
			Tag parent = root.GetChild("parent");
			
			AssertEquals(CHILDREN, parent.Children.Count, 2);
			AssertEquals(CHILDREN, parent.Children[1].Name,
					"daughter");
			
			
			Tag grandparent = root.GetChild("grandparent");
			
			AssertEquals(CHILDREN, grandparent.Children.Count, 2);
			// recursive fetch of children
			AssertEquals(CHILDREN, grandparent.GetChildren(true).Count, 6);		
			AssertEquals(CHILDREN, grandparent.GetChildren("son", true).Count, 2);	
			
			Tag grandparent2 = root.GetChild("grandparent2");
			AssertEquals(CHILDREN, grandparent2.GetChildren("child", true)
					.Count, 5);
			AssertEquals(CHILDREN, grandparent2.GetChild("daughter", true)
                ["birthday"],GetDate(1976,04,18));
			
			Tag files = root.GetChild("files");
			
			AssertEquals(CHILDREN, files.GetChildrenValues("content"),
					List("c:/file1.txt", "c:/file2.txt", "c:/folder"));
			
			Tag matrix = root.GetChild("matrix");
			
			AssertEquals(CHILDREN, matrix.GetChildrenValues("content"),
					List(List(1,2,3),List(4,5,6)));		
		}
Пример #9
0
		private static void TestBooleans(Tag root) {		
			Console.WriteLine("Doing bool tests...");
	
			AssertEquals(BOOLEAN_DECLARATIONS, root.GetChild("light-on").Value, true);
			AssertEquals(BOOLEAN_DECLARATIONS, root.GetChild("light-off").Value, false);
			AssertEquals(BOOLEAN_DECLARATIONS, root.GetChild("light1").Value, true);
			AssertEquals(BOOLEAN_DECLARATIONS, root.GetChild("light2").Value, false);
		}
Пример #10
0
		private static void TestNumbers(Tag root) {		
			Console.WriteLine("Doing number tests...");
			
			Console.WriteLine("    Testing ints...");
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("int1").Value, 0);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("int2").Value, 5);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("int3").Value, -100);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("int4").Value, 234253532);
			
			Console.WriteLine("    Testing longs...");
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("long1").Value, 0L);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("long2").Value, 5L);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("long3").Value, 5L);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("long4").Value, 3904857398753453453L);		
			
			Console.WriteLine("    Testing floats...");
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("float1").Value, 1F);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("float2").Value, .23F);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("float3").Value, -.34F);
	
			Console.WriteLine("    Testing doubles...");
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("double1").Value, 2D);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("double2").Value, -.234D);
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("double3").Value, 2.34D);
			
			Console.WriteLine("    Testing decimals (BigDouble in Java)...");
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("decimal1").Value,
					Convert.ToDecimal("0"));
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("decimal2").Value,
					Convert.ToDecimal("11.111111"));
			AssertEquals(NUMBER_DECLARATIONS, root.GetChild("decimal3").Value,
					Convert.ToDecimal("234535.3453453453454345345341242343"));		
		}
Пример #11
0
		private static void TestCharacters(Tag root) {		
			Console.WriteLine("Doing character tests...");
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char1").Value, 'a');
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char2").Value, 'A');
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char3").Value, '\\');
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char4").Value, '\n');
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char5").Value, '\t');
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char6").Value, '\'');
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char7").Value, '"');
			
			Console.WriteLine("    Doing unicode character tests...");
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char8").Value, '\u65e5');
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char9").Value, '\uc5ec');
			AssertEquals(CHARACTER_DECLARATIONS, root.GetChild("char10").Value, '\u0437');
		}
Пример #12
0
		////////////////////////////////////////////////////////////////////////////
		// Basic Types Tests
		////////////////////////////////////////////////////////////////////////////
		
		private static void TestStrings(Tag root) {
			Console.WriteLine("Doing string tests...");
			Console.WriteLine("    Doing basic tests including new line handling...");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string1").Value, "hello");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string2").Value, "hi");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string3").Value, "aloha");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string4").Value, "hi there");		
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string5").Value, "hi there joe");		
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string6").Value, "line1\nline2");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string7").Value, "line1\nline2");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string8").Value, "line1\nline2\nline3");			
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string9").Value,
					"Anything should go in this line without escapes \\ \\\\ \\n " +
					"\\t \" \"\" ' ''");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("string10").Value, "escapes \"\\\n\t");
			
			Console.WriteLine("    Checking unicode strings...");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("japanese").Value, "\u65e5\u672c\u8a9e");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("korean").Value, "\uc5ec\ubcf4\uc138\uc694");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("russian").Value,
					"\u0437\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u043b\u0442\u0435");
			
			Console.WriteLine("    More new line tests...");
			AssertContains(STRING_DECLARATIONS, (string)root.GetChild("xml").Value,
					"<text>Hi there!</text>");
			AssertEquals(STRING_DECLARATIONS, root.GetChild("line_test").Value,
					"\nnew line above and below\n");
		}
Пример #13
0
 private Tag ConstructTag(List<Token> toks)
 {
     if (toks.Count == 0)
     this.ParseException("Internal Error: Empty token list", this.lineNumber, -2);
       Token token1 = toks[0];
       if (token1.literal)
     toks.Insert(0, token1 = new Token(this, "content", -1, -1));
       else if (token1.type != Type.IDENTIFIER)
     this.ExpectingButGot("IDENTIFIER", (object) string.Concat(new object[4]
     {
       (object) token1.type,
       (object) " (",
       (object) token1.text,
       (object) ")"
     }), token1.line, token1.position);
       int count = toks.Count;
       Tag tag;
       if (count == 1)
       {
     tag = new Tag(token1.text);
       }
       else
       {
     int tpos1 = 1;
     Token token2 = toks[1];
     if (token2.type == Type.COLON)
     {
       if (count == 2 || toks[2].type != Type.IDENTIFIER)
     this.ParseException("Colon (:) encountered in unexpected location.", token2.line, token2.position);
       Token token3 = toks[2];
       tag = new Tag(token1.text, token3.text);
       tpos1 = 3;
     }
     else
       tag = new Tag(token1.text);
     int tpos2 = this.AddTagValues(tag, (IList<Token>) toks, tpos1);
     if (tpos2 < count)
       this.AddTagAttributes(tag, (IList<Token>) toks, tpos2);
       }
       return tag;
 }
Пример #14
0
 private int AddTagValues(Tag tag, IList<Token> toks, int tpos)
 {
     int count = toks.Count;
       int index;
       for (index = tpos; index < count; ++index)
       {
     Token token = toks[index];
     if (token.literal)
     {
       if (token.type == Type.DATE && index + 1 < count && toks[index + 1].type == Type.TIME)
       {
     SDLDateTime dt = (SDLDateTime) token.GetObjectForLiteral();
     TimeSpanWithZone tswz = (TimeSpanWithZone) toks[index + 1].GetObjectForLiteral();
     if (tswz.Days != 0)
     {
       tag.AddValue((object) dt);
       tag.AddValue((object) new TimeSpan(tswz.Days, tswz.Hours, tswz.Minutes, tswz.Seconds, tswz.Milliseconds));
       if (tswz.TimeZone != null)
         this.ParseException("TimeSpan cannot have a timezone", token.line, token.position);
     }
     else
       tag.AddValue((object) Parser.Combine(dt, tswz));
     ++index;
       }
       else
       {
     object objectForLiteral = token.GetObjectForLiteral();
     if (objectForLiteral is TimeSpanWithZone)
     {
       TimeSpanWithZone timeSpanWithZone = (TimeSpanWithZone) objectForLiteral;
       if (timeSpanWithZone.TimeZone != null)
         this.ExpectingButGot("TIME SPAN", (object) "TIME (component of date/time)", token.line, token.position);
       tag.AddValue((object) new TimeSpan(timeSpanWithZone.Days, timeSpanWithZone.Hours, timeSpanWithZone.Minutes, timeSpanWithZone.Seconds, timeSpanWithZone.Milliseconds));
     }
     else
       tag.AddValue(objectForLiteral);
       }
     }
     else if (token.type != Type.IDENTIFIER)
       this.ExpectingButGot("LITERAL or IDENTIFIER", (object) token.type, token.line, token.position);
     else
       break;
       }
       return index;
 }
Пример #15
0
		public static void TestAttributes(Tag root) {
			Console.WriteLine("Doing attribute tests...");
	
			AssertEquals(ATTRIBUTES, root.GetChild("atts1").Attributes,
					Map("name","joe"));
			AssertEquals(ATTRIBUTES, root.GetChild("atts2").Attributes,
					Map("size",5));	
			AssertEquals(ATTRIBUTES, root.GetChild("atts3").Attributes,
					Map("name","joe","size",5));	
			AssertEquals(ATTRIBUTES, root.GetChild("atts4").Attributes,
					Map("name","joe","size",5,"smoker",false));
			AssertEquals(ATTRIBUTES, root.GetChild("atts5").Attributes,
					Map("name","joe","smoker",false));
			AssertEquals(ATTRIBUTES, root.GetChild("atts6").Attributes,
					Map("name","joe","smoker",false));	
			AssertEquals(ATTRIBUTES, root.GetChild("atts7").Attributes,
					Map("name","joe"));
			AssertEquals(ATTRIBUTES, root.GetChild("atts8").Attributes,
					Map("name","joe","size",5,"smoker",false,"text","hi","birthday",
							GetDate(1972,5,23)));
			AssertEquals(ATTRIBUTES, root.GetChild("atts9")["key"],
					new byte[] {109, 121, 107, 101, 121});
		}	
Пример #16
0
		public static void TestValuesAndAttributes(Tag root) {
			Console.WriteLine("Doing values and attributes tests...");
	
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts1")
					.Values, List("joe"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts1")
					.Attributes, Map("size", 5));		
			
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts2")
					.Values, List("joe"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts2")
					.Attributes, Map("size", 5));			
			
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts3")
					.Values, List("joe"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts3")
					.Attributes, Map("size", 5));
	
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts4")
					.Values, List("joe"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts4")
					.Attributes, Map("size", 5, "weight", 160, "hat", "big"));
			
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts5")
					.Values, List("joe", "is a\n nice guy"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts5")
					.Attributes, Map("size", 5, "smoker", false));		
	
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts6")
					.Values, List("joe", "is a\n nice guy"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts6")
					.Attributes, Map("size", 5, "house", "big and\n blue"));
			
			//////////
			
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts7")
					.Values, List("joe", "is a\n nice guy"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts7")
					.Attributes, Map("size", 5, "smoker", false));
			
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts8")
					.Values, List("joe", "is a\n nice guy"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts8")
					.Attributes, Map("size", 5, "smoker", false));
			
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts9")
					.Values,List("joe", "is a\n nice guy"));
			AssertEquals(VALUES_AND_ATTRIBUTES, root.GetChild("valatts9")
					.Attributes, Map("size", 5, "smoker", false));			
		}	
Пример #17
0
		private static void TestNull(Tag root) {		
			Console.WriteLine("Doing null test...");
	
			AssertEquals(NULL_DECLARATION, root.GetChild("nothing").Value, null);
		}	
Пример #18
0
		public static void TestNamespaces(Tag root) {
			Console.WriteLine("Doing namespaces tests...");
			
			AssertEquals(NAMESPACES, root.GetChildrenForNamespace("person", true)
					.Count, 8);
			
			Tag grandparent2 = root.GetChild("grandparent3");
			
			// get only the attributes for Akiko in the public namespace
			AssertEquals(NAMESPACES, grandparent2.GetChild("daughter", true)
                    .GetAttributesForNamespace("public"), Map("name", "Akiko",
							"birthday", GetDate(1976,04,18)));
		}
Пример #19
0
		private static void TestDates(Tag root) {
			Console.WriteLine("Doing date tests...");
	
			AssertEquals(DATE_DECLARATIONS, root.GetChild("date1").Value,
					GetDate(2005,12,31));
			AssertEquals(DATE_DECLARATIONS, root.GetChild("date2").Value,
					GetDate(1882,5,2));
			AssertEquals(DATE_DECLARATIONS, root.GetChild("date3").Value,
					GetDate(1882,5,2));		
			AssertEquals(DATE_DECLARATIONS, root.GetChild("_way_back").Value,
					GetDate(582,9,16));			
		}
Пример #20
0
		private static void TestTimeSpans(Tag root) {
			Console.WriteLine("Doing time span tests...");
	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time1").Value,
					new TimeSpan(0,12,30,0,0));
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time2").Value,
					new TimeSpan(0,24,0,0,0));
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time3").Value,
					new TimeSpan(0,1,0,0,0));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time4").Value,
					new TimeSpan(0,1,0,0,0));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time5").Value,
					new TimeSpan(0,12,30,2,0));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time6").Value,
					new TimeSpan(0,12,30,23,0));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time7").Value,
					new TimeSpan(0,12,30,23,100));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time8").Value,
					new TimeSpan(0,12,30,23,120));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time9").Value,
					new TimeSpan(0,12,30,23,123));
			
			Console.WriteLine("    Checking time spans with days...");
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time10").Value,
					new TimeSpan(34,12,30,23,100));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time11").Value,
					new TimeSpan(1,12,30,0,0));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time12").Value,
					new TimeSpan(5,12,30,23,123));
			
			Console.WriteLine("    Checking negative time spans...");
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time13").Value,
					new TimeSpan(0,-12,-30,-23,-123));	
			AssertEquals(TIME_SPAN_DECLARATIONS, root.GetChild("time14").Value,
					new TimeSpan(-5,-12,-30,-23,-123));
		}
Пример #21
0
		private static void TestDateTimes(Tag root) {
			Console.WriteLine("Doing date time tests...");
	
			AssertEquals(DATE_TIME_DECLARATIONS, root.GetChild("date_time1").Value,
					GetDateTime(2005,12,31,12,30,0,0,null));	
			AssertEquals(DATE_TIME_DECLARATIONS, root.GetChild("date_time2").Value,
					GetDateTime(1882,5,2,12,30,0,0,null));	
			AssertEquals(DATE_TIME_DECLARATIONS, root.GetChild("date_time3").Value,
					GetDateTime(2005,12,31,1,0,0,0,null));	
			AssertEquals(DATE_TIME_DECLARATIONS, root.GetChild("date_time4").Value,
					GetDateTime(1882,5,2,1,0,0,0,null));	
			AssertEquals(DATE_TIME_DECLARATIONS, root.GetChild("date_time5").Value,
					GetDateTime(2005,12,31,12,30,23,120,null));	
			AssertEquals(DATE_TIME_DECLARATIONS, root.GetChild("date_time6").Value,
					GetDateTime(1882,5,2,12,30,23,123,null));	
			
			Console.WriteLine("    Checking timezones...");
			AssertEquals(DATE_TIME_DECLARATIONS, root.GetChild("date_time7").Value,
					GetDateTime(1882,5,2,12,30,23,123,"JST"));	
			AssertEquals(DATE_TIME_DECLARATIONS, root.GetChild("date_time8").Value,
					GetDateTime(985,04,11,12,30,23,123,"PST"));	
		}
Пример #22
0
		private static void TestTagWriteParse(string fileName, Tag root) {
			
			Console.WriteLine("Doing Tag write/parse tests for file " + fileName + "...");
			
			// Write out the contents of a tag, read the output back in and
			// test for equality.  This is a very rigorous test for any non-trivial
			// file.  It tests the parsing, output, and .equals implementation.
			Console.WriteLine("    Write out the tag and read it back in...");
			
			AssertEquals(TAG_WRITE_PARSE, root, new Tag("test")
					.ReadString(root.ToString()).GetChild("root"));
			
			
		}
Пример #23
0
		private static void TestBinaries(Tag root) {
			Console.WriteLine("Doing binary tests...");
			AssertEquals(BINARY_DECLARATIONS, root.GetChild("hi").Value,
				new byte[] {104,105});	
			AssertEquals(BINARY_DECLARATIONS, root.GetChild("png").Value,
				Convert.FromBase64String(
					"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAKnRFWHRDcmVhdGlvbiBUaW1l" +
					"AERpIDQgTXJ6IDIwMDMgMDA6MjQ6MDQgKzAxMDDdSQ6OAAAAB3RJTUUH0wMEAAcllPlrJgAA" +
					"AAlwSFlzAAAK8AAACvABQqw0mAAAAARnQU1BAACxjwv8YQUAAADQSURBVHjaY2CgEDCCyZn/" +
					"3YHkDhL1ejCkM+5kgXJ2zDQmXueShwwMh9+ALWSEGcCQfhZIvHlDnAk8PAwMHBxgJtyAa7bX" +
					"UdT8/cvA8Ps3hP7zB4FBYn/+vGbweqyJaoCmpiaKASDFv35BNMBoZMzwGKKOidJYoNgAuBdm" +
					"naXQgHRKDfgagxD89w8S+iAaFICwGIHFAgjrHUczAByySAaAMEgDLBphhv7/D8EYLgDZhAxA" +
					"mkAKYYbAMMwwDAOQXYDuDXRXgDC6AR7SW8jITNQAACjZgdj4VjlqAAAAAElFTkSuQmCC"						
				));		
		}
Пример #24
0
Файл: Tag.cs Проект: Zeludon/FEZ
 public bool RemoveChild(Tag child)
 {
     this.childrenDirty = true;
       return this.children.Remove(child);
 }
Пример #25
0
 private void AddChildren(Tag parent)
 {
     List<Token> lineTokens;
       while ((lineTokens = this.GetLineTokens()) != null)
       {
     int count = lineTokens.Count;
     if (lineTokens[0].type == Type.END_BLOCK)
       return;
     if (lineTokens[count - 1].type == Type.START_BLOCK)
     {
       Tag tag = this.ConstructTag(lineTokens.GetRange(0, count - 1));
       this.AddChildren(tag);
       parent.AddChild(tag);
     }
     else
       parent.AddChild(this.ConstructTag(lineTokens));
       }
       this.ParseException("No close block (}).", this.lineNumber, -2);
 }