public void Constructor_ValueWithQuotes_GeneratesCorrectContent( string nodeText, string expectedContent, Type expectedType) { var node = new HamlNodeHtmlAttribute(new HamlSourceFileMetrics(0, 0, 0, 0), nodeText); Assert.That(node.Children.First().Children.First(), Is.InstanceOf(expectedType)); Assert.That(node.Children.First().Children.First().Content, Is.EqualTo(expectedContent)); }
public void Constructor_ValidAttributeStrings_ExtractsQuoteCharCorrectly( string attributeString, char expectedQuoteChar) { var tag = new HamlNodeHtmlAttribute(new HamlSourceFileMetrics(0, 0, 0, 0), attributeString); Assert.That(tag.QuoteChar, Is.EqualTo(expectedQuoteChar)); }
public void Constructor_NormalUse_GeneratesCorrectNameValuePair(string input, string name, string value) { var node = new HamlNodeHtmlAttribute(new HamlSourceFileMetrics(0, 0, 0, 0), input); Assert.That(node.Name, Is.EqualTo(name)); if (string.IsNullOrEmpty(value)) Assert.That(node.Children, Is.Empty); else Assert.That(node.Children.First().Children.First().Content, Is.EqualTo(value)); }
private void ParseChildren(string attributeCollection) { int index = 1; char closingBracketChar = attributeCollection[0] == '{' ? '}' : ')'; Stack <char> stack = new Stack <char>(); char quote = '\0'; int tokenStartPosition = 0; while (index < attributeCollection.Length) { switch (attributeCollection[index]) { case '{': stack.Push(attributeCollection[index]); break; case '\'': case '\"': if (quote == '\0') { tokenStartPosition = index + 1; quote = attributeCollection[index]; } else { // TODO: Match to same type } break; default: break; } string nameValuePair = GetNextAttributeToken(attributeCollection, closingBracketChar, ref index); if (!string.IsNullOrEmpty(nameValuePair)) { AddChild(HamlNodeHtmlAttribute.FromNameValuePair(SourceFileLineNum, nameValuePair)); } index++; } }
public void Constructor_ValueWithoutQuotes_ConvertsValueToVariable() { var node = new HamlNodeHtmlAttribute(new HamlSourceFileMetrics(0, 0, 0, 0), "a=#{b}"); Assert.That(node.Children.First(), Is.InstanceOf<HamlNodeTextVariable>()); Assert.That(node.Children.First().Content, Is.EqualTo("#{b}")); }
public void Constructor_NormalUse_RepresentsValueAsTextContainer() { var node = new HamlNodeHtmlAttribute(new HamlSourceFileMetrics(0, 0, 0, 0), "a='b'"); Assert.That(node.Children.First(), Is.InstanceOf<HamlNodeTextContainer>()); }