public void Tokenize_With_Preprocess_ToUppercase_Postprocess_Trim_Test() { // Defines the Columns of a File: ColumnDefinition[] columns = new[] { new FixedLengthTokenizer.ColumnDefinition(0, 10), new FixedLengthTokenizer.ColumnDefinition(10, 20), }; // The Postprocessing Function on the Column value: Preprocessor preprocessor = new Preprocessor(s => s.ToUpperInvariant()); Postprocessor postprocessor = new Postprocessor(s => s.Trim()); // The Original Tokenizer, which tokenizes the line: ITokenizer decoratedTokenizer = new FixedLengthTokenizer(columns); ITokenizer tokenizer = new TokenizerProcessingDecorator(decoratedTokenizer, preprocessor, postprocessor); string input = new StringBuilder() .AppendLine(" Philipp Wagner ") .ToString(); string[] result = tokenizer.Tokenize(input); Assert.AreEqual("PHILIPP", result[0]); Assert.AreEqual("WAGNER", result[1]); }
public void TestTokenize2() { var tokenizer = new FixedLengthTokenizer { Columns = new[] { new Range(1, 2), new Range(3) } }; var result = tokenizer.Tokenize(" 1Person 1 "); Assert.AreEqual(2, result.Count); Assert.AreEqual(" 1", result.ReadRawString(0)); Assert.AreEqual("Person 1 ", result.ReadRawString(1)); }
public void Tokenize_Line_Test() { var columns = new[] { new FixedLengthTokenizer.ColumnDefinition(0, 10), new FixedLengthTokenizer.ColumnDefinition(10, 20), }; var tokenizer = new FixedLengthTokenizer(columns); var input = new StringBuilder() .AppendLine("Philipp Wagner ") .ToString(); var result = tokenizer.Tokenize(input); Assert.AreEqual("Philipp ", result[0]); Assert.AreEqual("Wagner ", result[1]); }