1
A
回答
2
一些它看起來並不像StringSpec
公開此信息,但可以延長StringSpec
這樣做。例如: -
class Spec : StringSpec() {
init {
"triangle.stl" { testCase ->
println(testCase.name)
}
}
operator fun String.invoke(test: (TestCase) -> Unit): TestCase {
var tc: TestCase? = null
tc = invoke(fun() { test(tc!!) })
return tc
}
}
或避免與exsting String.invoke
,你可以用自己的語法擴展它的功能衝突。例如:
class Spec : StringSpec() {
init {
"triangle.stl" testCase {
println(name)
}
}
infix fun String.testCase(test: TestCase.() -> Unit): TestCase {
var tc: TestCase? = null
tc = invoke { test(tc!!) }
return tc
}
}
1
您將不得不親自存儲對該字符串的引用。像
class stl : StringSpec() {
init {
val spek = "triangle.stl"
spek {
// use spek in here
}
}
}
相關問題
- 1. 特定字符串格式正則表達式<><><>
- 2. 從表達式<Func <TModel,字符串>>轉換爲表達式<Func <TModel,bool >>
- 3. 是否可能表達<Func <T, TProp>>的集合?
- 4. PHP表達<<< EOB
- 5. 什麼是和如何使用'<<< END_JAVASCRIPT'字符串?
- 6. 正則表達式表達,如果有像串的任何特殊字符(!,@<#,$,%<^ <等)
- 7. LINQ表達式來尋找是否有我有一個字符串的兩份名單,<code>List1</code>和<code>list2</code>,其中<code>List1</code>是<code>Foo</code>類型的對象的列表中<code>fooList</code>一個屬性字符串
- 8. 正則表達式的表達,去除<div class...</div>
- 9. 將lambda表達式轉換爲Func <IObserver <char>,IDisposable>
- 10. Lambda表達式與<bool>和System.Nullable <bool>
- 11. 的LINQ的IEnumerable <IGrouping <字符串,類>>返回列表<Class>
- 12. 搜索一個HashMap <字符串,ArrayList的<Users>>或HashMap中<字符串,HashSet的<Users>>
- 13. 更改列表的顯示格式<KeyValuePair <字符串,字符串>>
- 14. PHP內使用Gettext <<< EOF字符串
- 15. 表達式<Action<T>> methodCall
- 16. 排序列表<keyValuePair <字符串,字符串>>
- 17. 實體框架字符串數據類型使用>,> =,<,<=運算符:Lambda表達式
- 18. 在表達式中解析字符串爲DateTimeOffset <Func <T, bool>>
- 19. 如何轉換`詞典<字符串,字典<字符串,列表<MyCustomClass >>>``到詞典<字符串,列表<MyCustomClass >>`
- 20. 什麼意思的符號在java中「<<<」「<< =」「<<」
- 21. Func鍵<>與lambda表達式
- 22. Strip <?xml和<!DOCTYPE from字符串
- 23. 詞典<字符串,MyClass的>爲List <KeyValuePair <字符串,字符串>>其中KeyValuePair值是MyClass.ToString()
- 24. 獲得指數<HashMap的<字符串,字符串>>
- 25. 如何動態分配lambda <表達式<delegate>>到表達式<delegate>
- 26. 解析字符串以特定的格式 - <Username>/<Password> @<Host>
- 27. 的ArrayList <HashMap中<字符串,字符串>>爲String []
- 28. 什麼是我的檔案中的「<<<<<<< head」?
- 29. <xsl:import> in <xsl:for-each>是否有可能或替代?
- 30. 表要字典<字符串,對象>使用Lambda表達式