diff --git a/Source/Data/CodeNote.cs b/Source/Data/CodeNote.cs index 92b6d525..dd3f50fd 100644 --- a/Source/Data/CodeNote.cs +++ b/Source/Data/CodeNote.cs @@ -661,14 +661,14 @@ private static bool IsValue(Token token) if (token.StartsWith("0x")) index += 2; - if (index == token.Length) + if (index == token.Length || !IsHexDigit(token[index])) return false; - while (IsHexDigit(token[index])) + do { if (++index == token.Length) return true; - } + } while (IsHexDigit(token[index])); while (index < token.Length && Char.IsWhiteSpace(token[index])) index++; @@ -680,7 +680,7 @@ private static bool IsValue(Token token) while (index < token.Length && Char.IsWhiteSpace(token[index])) index++; - if (!IsHexDigit(token[index])) + if (index == token.Length || !IsHexDigit(token[index])) return false; do diff --git a/Tests/Data/CodeNoteTests.cs b/Tests/Data/CodeNoteTests.cs index 72a7a615..4d5a441f 100644 --- a/Tests/Data/CodeNoteTests.cs +++ b/Tests/Data/CodeNoteTests.cs @@ -371,5 +371,23 @@ public void TestPossibleButNotEnum() Assert.That(n.Size, Is.EqualTo(FieldSize.None)); Assert.That(n.Values.Count(), Is.EqualTo(0)); } + + [Test] + public void TestUnboundedRangeEnums() + { + var n = new CodeNote(4, "[8-bit] Chars\n" + + "0-=!\n" + // 0 starts a range, but without an end, it's not valid + "-9=?\n" + // This dash is seen as an indent marker. the mapping "9=?" is processed. + "-=$\n" + // These are all seen as prefix characters and are ignored. + "X=0-" + // 0 starts a range, but without an end, it's not valid + "Y=-9" + // 9 ends a range, but without a start, it's not valid + "Z=-"); // range has neither a start nor an end. it's not valid + + Assert.That(n.Summary, Is.EqualTo("Chars")); + Assert.That(n.Size, Is.EqualTo(FieldSize.Byte)); + Assert.That(n.Values.Count(), Is.EqualTo(1)); + Assert.That(n.Values.First().Key, Is.EqualTo("9")); + Assert.That(n.Values.First().Value, Is.EqualTo("?")); + } } }