public void TestLoadRuleWithLoop() { IProjectNode p = ProjectSerializer.LoadString("rule root {\r\n\tloop 1 2 {\r\n\t\tliteral a\r\n\t}\r\n}\r\n", null, null); Assert.AreEqual(1, p.Children.Count, "Didn't find the rule."); IProjectNode rule = p.Children[0]; Assert.AreEqual(ProjectNodeType.RuleDeclaration, rule.NodeType); RuleNode rn = rule as RuleNode; Assert.IsNotNull(rn); Assert.AreEqual(1, rn.Children.Count, "Didn't find the command block."); Assert.AreEqual("root", rn.Name); CommandBlockNode cbn = rn.Children[0] as CommandBlockNode; Assert.IsNotNull(cbn); Assert.AreEqual(1, cbn.Children.Count); Whee.WordBuilder.Model.Commands.CommandBase cb = cbn.Children[0] as Whee.WordBuilder.Model.Commands.CommandBase; Assert.IsInstanceOfType(typeof(Whee.WordBuilder.Model.Commands.LoopCommand), cb); Assert.AreEqual(1, cb.Children.Count); }
private void LoadWeightedCommand() { bool found = false; double probability = 0; Token probabilityToken = m_serializer.ReadNumericToken(this, ref probability, out found); if (probabilityToken != null) { Weight = probability; Token command = m_serializer.ReadTextToken(this); if (command != null) { Model.Commands.CommandBase cb = Model.Commands.CommandBase.FindCommand(command.Text); if (cb != null) { command.Type = TokenType.Command; cb.Index = command.Offset; cb.LoadCommand(m_serializer); Command = cb; Children.Add(cb); //cb.Length = m_serializer.Position - cb.Index; } else { m_serializer.Warn(string.Format("Command '{0}' not found.", command.Text), this); command.Type = TokenType.Error; Successful = false; } } else { m_serializer.Warn("Expected a command", this); probabilityToken.Type = TokenType.Error; Successful = false; } } else if (found) { m_serializer.Warn("Expected a probability expressed as a decimal number.", this); Successful = false; m_serializer.ReadTextToken(this).Type = TokenType.Error; } }