public static List <(AspectMetadata aspect, AspectTestSuite tests)> ParseAspects( this IEnumerable <string> jsonFileNames, List <string> testFileNames, Context context) { var aspects = new List <(AspectMetadata aspect, AspectTestSuite tests)>(); foreach (var file in jsonFileNames) { var fi = new FileInfo(file); var aspect = JsonParser.AspectFromJson(context, File.ReadAllText(file), fi.Name); if (aspect == null) { continue; } var testName = aspect.Name + ".test.csv"; var testPath = testFileNames.FindTest(testName); AspectTestSuite tests = null; if (!string.IsNullOrEmpty(testPath) && File.Exists(testPath)) { tests = AspectTestSuite.FromString(aspect, File.ReadAllText(testPath)); } aspects.Add((aspect, tests)); } return(aspects); }
private IExpression MustMatchJsonWithOr() { var json = "{" + "\"name\":\"test\"," + "\"description\":\"test\"," + "\"$mustMatch\":{\"a\":\"b\",\"x\":\"y\"}}"; return(JsonParser.AspectFromJson(new Context(), json, "test.json")); }
public void MaxSpeedAspect_Evaluate_CorrectMaxSpeed() { var json = "{\"name\": \"legal_maxspeed_be\",\"description\": \"Gives, for each type of highway, which the default legal maxspeed is in Belgium. This file is intended to be reused for in all vehicles, from pedestrian to car. In some cases, a legal maxspeed is not really defined (e.g. on footways). In that case, a socially acceptable speed should be taken (e.g.: a bicycle on a pedestrian path will go say around 12km/h)\",\"unit\": \"km/h\",\"$max\": {\"maxspeed\": \"$parse\",\"highway\": {\"residential\": 30},\"ferry\":5}}"; var aspect = JsonParser.AspectFromJson(null, json, null); var tags = new Dictionary <string, string> { { "maxspeed", "42" }, { "highway", "residential" }, { "ferry", "yes" } }; Assert.Equal("tags -> pdouble", string.Join(", ", aspect.Types)); Assert.Equal(42d, new Apply(aspect, new Constant(tags)).Evaluate(null)); }
public void MaxSpeed_AnalyzeTags_AllTagsReturned() { var json = "{\"name\": \"legal_maxspeed_be\",\"description\": \"Gives, for each type of highway, which the default legal maxspeed is in Belgium. This file is intended to be reused for in all vehicles, from pedestrian to car. In some cases, a legal maxspeed is not really defined (e.g. on footways). In that case, a socially acceptable speed should be taken (e.g.: a bicycle on a pedestrian path will go say around 12km/h)\"," + "\"unit\": \"km/h\"," + "\"$max\": {\"maxspeed\": \"$parse\",\"highway\": {\"residential\": 30},\"ferry\":5}}"; var aspect = JsonParser.AspectFromJson(null, json, null); Assert.Equal( new Dictionary <string, HashSet <string> > { { "maxspeed", new HashSet <string>() }, { "highway", new HashSet <string> { "residential" } }, { "ferry", new HashSet <string>() } }, aspect.PossibleTags()); }