简体   繁体   English

比较前的 Fitnesse Trim String 数据

[英]Fitnesse Trim String data before comparison

I wanted to ask if there is a way to trim String data before comparing it with the data in the table.我想问一下是否有办法在将字符串数据与表中的数据进行比较之前对其进行修剪。 For example, if we have例如,如果我们有

|MyCompareClass|
|getString?    |
|string1       |

And the result of getString() will be "string1 ". getString() 的结果将是“string1”。 I want the comparison to be green and not Expected "string1".我希望比较为绿色而不是预期的“string1”。 I'm looking for a way to do it without modifying the MyCompareClass source code.我正在寻找一种无需修改 MyCompareClass 源代码的方法。 Any ideas?有任何想法吗?

You can write a custom string compare operator class:您可以编写自定义字符串比较运算符类:

public class MyCustomCompare: CellOperator, CompareOperator<Cell> {
    public bool CanCompare(TypedValue actual, Tree<Cell> expected) {
        return actual.Type == typeof(string);
    }

    public bool Compare(TypedValue actual, Tree<Cell> expected) {
        return actual.Value.ToString().Trim() == expected.Value.Text;
    }
}

Then register your class with the Fitnesse configure fixture:然后使用Fitnesse配置夹具注册您的课程:

|configure|processor|add operator|MyCustomCompare|

You could put !-string1 -!你可以把!-string1 -! in your cell.在你的牢房里。 All other options I can think of involve code changes to either SUT or fixture.我能想到的所有其他选项都涉及对 SUT 或夹具的代码更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM