public void SimpleApiTest() { var stream = new InputStream(SIMPLE_API); var tokenizer = new Tokenizer(stream); var parser = new NebulaParser(tokenizer); var result = parser.Parse("sampleModule"); var apiNode = result.SearchByType <ApiNode>().FirstOrDefault(); Assert.NotNull(apiNode); Assert.AreEqual("SimpleApi", apiNode.Name); var config = apiNode.SearchByType <ConfigNode>().FirstOrDefault(); Assert.NotNull(config); var configNodes = config.Nodes; Assert.AreEqual(3, configNodes.Count); var functions = apiNode.SearchByType <FunctionNode>(); Assert.AreEqual(1, functions.Count); var func = functions.FirstOrDefault(); Assert.NotNull(func); Assert.AreEqual("getDevices", func.Name); Assert.AreEqual(TokenType.GetFunction, func.Method); Assert.AreEqual("/devices", func.Url); Assert.AreEqual("array", func.ReturnType.Name); Assert.IsTrue(func.ReturnType.Generic); Assert.AreEqual("Device", func.ReturnType.GenericType); }
private ModuleNode BuildModule(string inputFile) { _buildCount++; _buildProgress = Math.Floor((_buildCount / _totalFiles) * 100); Console.WriteLine($"[{_buildCount}/{_totalFiles} ({_buildProgress}%)] Processing {inputFile}"); var moduleName = inputFile.Replace(Path.DirectorySeparatorChar, '.').Replace(".neb", ""); var absoluteFile = Path.Combine(_currentProject.SourceDirectory, inputFile); var parser = new NebulaParser(absoluteFile); return(parser.Parse(moduleName)); }
public void EntityFieldTest() { var stream = new InputStream(SIMPLE_ENTITY); var tokenizer = new Tokenizer(stream); var parser = new NebulaParser(tokenizer); var result = parser.Parse("sampleModule"); var fields = result.SearchByType <ArgumentNode>(); Assert.AreEqual(1, fields.Count); }
public void ComplexEntityTest() { var stream = new InputStream(COMPLEX_ENTITIES); var tokenizer = new Tokenizer(stream); var parser = new NebulaParser(tokenizer); var result = parser.Parse("sampleModule"); var entities = result.SearchByType <EntityNode>(); Assert.AreEqual(2, entities.Count); var complexDeviceNode = entities.FirstOrDefault(e => e.Name == "ComplexDevice"); Assert.NotNull(complexDeviceNode); Assert.AreEqual(4, complexDeviceNode.Fields.Count); var complexDeviceHistoryNode = entities.FirstOrDefault(e => e.Name == "ComplexDeviceHistory"); Assert.NotNull(complexDeviceHistoryNode); Assert.AreEqual(2, complexDeviceHistoryNode.Fields.Count); }
public void ComplexApiTest() { var stream = new InputStream(COMPLEX_API); var tokenizer = new Tokenizer(stream); var parser = new NebulaParser(tokenizer); var result = parser.Parse("sampleModule"); var api = result.SearchByType <ApiNode>().FirstOrDefault(); Assert.NotNull(api); var funcs = result.SearchByType <FunctionNode>(); Assert.AreEqual(3, funcs.Count); var getDevicesFunc = funcs.FirstOrDefault(f => f.Name == "getDevices"); Assert.NotNull(getDevicesFunc); Assert.AreEqual("/devices", getDevicesFunc.Url); Assert.AreEqual(TokenType.GetFunction, getDevicesFunc.Method); }
public void SimpleEntityTest() { var stream = new InputStream(SIMPLE_ENTITY); var tokenizer = new Tokenizer(stream); var parser = new NebulaParser(tokenizer); var result = parser.Parse("sampleModule"); Assert.IsAssignableFrom(typeof(ModuleNode), result); Assert.AreEqual("sampleModule", result.Name); var entityNodes = result.SearchByType <EntityNode>(); Assert.AreEqual(1, entityNodes.Count); Assert.IsAssignableFrom(typeof(EntityNode), entityNodes.FirstOrDefault()); var deviceNode = entityNodes.FirstOrDefault(); Assert.NotNull(deviceNode); }