我正在开发一个 twitter 文本 c# 库,并且 twitter 已经在他们的一致性测试中添加了一个双字 unicode 字符测试。
https://github.com/twitter/twitter-text-conformance/blob/master/validate.yml
这是针对上述文件运行的 nUnit 测试方法。
[Test]
public void TestDoubleWordUnicodeYamlRetrieval()
{
var yamlFile = "validate.yml";
Assert.IsTrue(File.Exists(conformanceDir + yamlFile), "Yaml file " + conformanceDir + yamlFile + " does not exist.");
var stream = new StreamReader(Path.Combine(conformanceDir, yamlFile));
var yaml = new YamlStream();
yaml.Load(stream);
var root = yaml.Documents[0].RootNode as YamlMappingNode;
var testNode = new YamlScalarNode("tests");
Assert.IsTrue(root.Children.ContainsKey(testNode), "Document is missing test node.");
var tests = root.Children[testNode] as YamlMappingNode;
Assert.IsNotNull(tests, "Test node is not YamlMappingNode");
var typeNode = new YamlScalarNode("lengths");
Assert.IsTrue(tests.Children.ContainsKey(typeNode), "Test type lengths not found in tests.");
var typeTests = tests.Children[typeNode] as YamlSequenceNode;
Assert.IsNotNull(typeTests, "lengths tests are not YamlSequenceNode");
var list = new List<dynamic>();
var count = 0;
foreach (YamlMappingNode item in typeTests)
{
var text = ConvertNode<string>(item.Children.Single(x => x.Key.ToString() == "text").Value) as string;
var description = ConvertNode<string>(item.Children.Single(x => x.Key.ToString() == "description").Value) as string;
Assert.DoesNotThrow(() => {text.Normalize(NormalizationForm.FormC);}, String.Format("Yaml couldn't parse a double word unicode string at test {0} - {1}.", count, description));
count++;
}
}
这是产生的错误: Vocus.TwitterText.Tests.ConformanceTest.TestDoubleWordUnicodeYamlRetrieval: Yaml 无法在测试 5 解析双字 unicode 字符串 - 计算基本多语言平面(双字)之外的 unicode 字符。意外异常:System.ArgumentException