/// <summary> /// Creates a new scan token. /// </summary> /// <param name="type">Type of characters found.</param> /// <param name="text">Characters found.</param> /// <param name="start">Position of the first character found.</param> /// <exception cref="ArgumentException">text was empty or null; type was <see cref="Mark"/> but text was more than one character; type was not understood.</exception> public ScanToken(ScanTokenType type, string text, ScanPosition start) { Text = NotNullOrEmpty(text, nameof(text)); Type = type; Start = start; switch (type) { case ScanTokenType.Mark: if (text.Length > 1) { throw new ArgumentException("Mark tokens must be a single character", nameof(text)); } End = start; break; case ScanTokenType.Word: case ScanTokenType.Space: End = start + (uint)text.Length; break; case ScanTokenType.Newline: End = new ScanPosition(start.Absolute + (uint)text.Length, start.Row + 1, 0); break; default: throw new ArgumentException($"{type} is not a supported scan token type", nameof(type)); } }
public void New_WithBadParameters_Throws(ScanTokenType type, string text, string badParameterName) { TestAction(() => new ScanToken(type, text, Start)) .Should().Throw <ArgumentException>() .Where(x => x.ParamName == badParameterName); }