Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
adf38a06
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
adf38a06
编写于
5月 25, 2012
作者:
J
James Strachan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added a working JS test case using the standard kotlin browser API for interacting with the DOM
上级
3702bdea
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
105 addition
and
12 deletion
+105
-12
js/js.libraries/src/core/dom.kt
js/js.libraries/src/core/dom.kt
+1
-0
js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java
js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java
+6
-1
js/js.tests/test/org/jetbrains/k2js/test/rhino/RhinoFunctionNativeObjectResultChecker.java
...js/test/rhino/RhinoFunctionNativeObjectResultChecker.java
+45
-0
js/js.tests/test/org/jetbrains/k2js/test/rhino/RhinoFunctionResultChecker.java
...jetbrains/k2js/test/rhino/RhinoFunctionResultChecker.java
+7
-3
js/js.tests/test/org/jetbrains/k2js/test/rhino/RhinoUtils.java
....tests/test/org/jetbrains/k2js/test/rhino/RhinoUtils.java
+17
-0
js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTest.java
...ts/test/org/jetbrains/k2js/test/semantics/StdLibTest.java
+26
-6
js/js.translator/testFiles/stdlib/cases/browserDocumentAccess.kt
...ranslator/testFiles/stdlib/cases/browserDocumentAccess.kt
+3
-2
未找到文件。
js/js.libraries/src/core/dom.kt
浏览文件 @
adf38a06
...
...
@@ -18,6 +18,7 @@ native public trait DOMImplementation {}
native
public
trait
DocumentType
:
Node
{}
native
public
trait
Element
:
Node
{
fun
appendChild
(
child
:
Node
)
:
Unit
=
js
.
noImpl
fun
getTextContent
()
:
String
=
js
.
noImpl
}
native
public
trait
Entity
:
Node
{}
native
public
trait
EntityReference
:
Node
{}
...
...
js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java
浏览文件 @
adf38a06
...
...
@@ -29,6 +29,7 @@ import java.io.File;
import
java.util.Collections
;
import
java.util.EnumSet
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
jetbrains
.
k2js
.
test
.
rhino
.
RhinoUtils
.
runRhinoTest
;
import
static
org
.
jetbrains
.
k2js
.
test
.
utils
.
JsTestUtils
.
convertFileNameToDotJsFile
;
...
...
@@ -107,10 +108,14 @@ public abstract class BasicTest extends TestWithEnvironment {
protected
void
runRhinoTests
(
@NotNull
List
<
String
>
outputFilePaths
,
@NotNull
RhinoResultChecker
checker
)
throws
Exception
{
for
(
String
outputFilePath
:
outputFilePaths
)
{
runRhinoTest
(
withAdditionalFiles
(
outputFilePath
),
checker
);
runRhinoTest
(
withAdditionalFiles
(
outputFilePath
),
checker
,
getRhinoTestVariables
()
);
}
}
protected
Map
<
String
,
Object
>
getRhinoTestVariables
()
throws
Exception
{
return
null
;
}
protected
static
String
casesDirectoryName
()
{
return
CASES
;
...
...
js/js.tests/test/org/jetbrains/k2js/test/rhino/RhinoFunctionNativeObjectResultChecker.java
0 → 100644
浏览文件 @
adf38a06
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jetbrains.k2js.test.rhino
;
import
org.jetbrains.annotations.Nullable
;
import
org.mozilla.javascript.NativeJavaObject
;
/**
* Assert that a Rhino function returns a Native Java object which when unwrapped is equal to the expecte result
*/
public
class
RhinoFunctionNativeObjectResultChecker
extends
RhinoFunctionResultChecker
{
public
RhinoFunctionNativeObjectResultChecker
(
@Nullable
String
namespaceName
,
String
functionName
,
Object
expectedResult
)
{
super
(
namespaceName
,
functionName
,
expectedResult
);
}
public
RhinoFunctionNativeObjectResultChecker
(
String
functionName
,
Object
expectedResult
)
{
super
(
functionName
,
expectedResult
);
}
@Override
protected
void
assertResultValid
(
Object
result
)
{
if
(
result
instanceof
NativeJavaObject
)
{
NativeJavaObject
nativeJavaObject
=
(
NativeJavaObject
)
result
;
Object
unwrap
=
nativeJavaObject
.
unwrap
();
super
.
assertResultValid
(
unwrap
);
}
else
{
super
.
assertResultValid
(
result
);
}
}
}
js/js.tests/test/org/jetbrains/k2js/test/rhino/RhinoFunctionResultChecker.java
浏览文件 @
adf38a06
...
...
@@ -20,12 +20,13 @@ import org.jetbrains.annotations.Nullable;
import
org.mozilla.javascript.Context
;
import
org.mozilla.javascript.Scriptable
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
* @author Pavel Talanov
*/
public
final
class
RhinoFunctionResultChecker
implements
RhinoResultChecker
{
public
class
RhinoFunctionResultChecker
implements
RhinoResultChecker
{
private
final
String
namespaceName
;
private
final
String
functionName
;
...
...
@@ -44,8 +45,11 @@ public final class RhinoFunctionResultChecker implements RhinoResultChecker {
@Override
public
void
runChecks
(
Context
context
,
Scriptable
scope
)
throws
Exception
{
Object
result
=
evaluateFunction
(
context
,
scope
);
assertTrue
(
"Result is not what expected! Expected: "
+
expectedResult
+
" Evaluated : "
+
result
,
result
.
equals
(
expectedResult
));
assertResultValid
(
result
);
}
protected
void
assertResultValid
(
Object
result
)
{
assertEquals
(
"Result of "
+
namespaceName
+
"."
+
functionName
+
"() is not what expected!"
,
expectedResult
,
result
);
String
report
=
namespaceName
+
"."
+
functionName
+
"() = "
+
Context
.
toString
(
result
);
System
.
out
.
println
(
report
);
}
...
...
js/js.tests/test/org/jetbrains/k2js/test/rhino/RhinoUtils.java
浏览文件 @
adf38a06
...
...
@@ -22,6 +22,8 @@ import org.mozilla.javascript.Scriptable;
import
java.io.FileReader
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @author Pavel Talanov
...
...
@@ -45,8 +47,23 @@ public final class RhinoUtils {
public
static
void
runRhinoTest
(
@NotNull
List
<
String
>
fileNames
,
@NotNull
RhinoResultChecker
checker
)
throws
Exception
{
runRhinoTest
(
fileNames
,
checker
,
null
);
}
public
static
void
runRhinoTest
(
@NotNull
List
<
String
>
fileNames
,
@NotNull
RhinoResultChecker
checker
,
Map
<
String
,
Object
>
variables
)
throws
Exception
{
Context
context
=
Context
.
enter
();
Scriptable
scope
=
context
.
initStandardObjects
();
if
(
variables
!=
null
)
{
Set
<
Map
.
Entry
<
String
,
Object
>>
entries
=
variables
.
entrySet
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
entries
)
{
String
name
=
entry
.
getKey
();
Object
value
=
entry
.
getValue
();
scope
.
put
(
name
,
scope
,
value
);
}
}
for
(
String
filename
:
fileNames
)
{
runFileWithRhino
(
filename
,
context
,
scope
);
}
...
...
js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTest.java
浏览文件 @
adf38a06
...
...
@@ -20,10 +20,13 @@ import org.jetbrains.annotations.NotNull;
import
org.jetbrains.k2js.config.EcmaVersion
;
import
org.jetbrains.k2js.facade.MainCallParameters
;
import
org.jetbrains.k2js.test.SingleFileTranslationTest
;
import
org.jetbrains.k2js.test.rhino.RhinoFunctionNativeObjectResultChecker
;
import
org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
java.util.Arrays
;
import
java.util.EnumSet
;
import
java.util.List
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
java.util.*
;
/**
* @author Pavel Talanov
...
...
@@ -34,9 +37,6 @@ public final class StdLibTest extends SingleFileTranslationTest {
super
(
"stdlib/"
);
}
public
void
testDummy
()
{
}
public
void
testBrowserDocumentAccessCompiles
()
throws
Exception
{
generateJavaScriptFiles
(
"browserDocumentAccess.kt"
,
MainCallParameters
.
noCall
(),
EcmaVersion
.
all
());
}
...
...
@@ -48,5 +48,25 @@ public final class StdLibTest extends SingleFileTranslationTest {
List
<
String
>
files
=
Arrays
.
asList
(
getInputFilePath
(
kotlinFilename
));
generateJavaScriptFiles
(
files
,
kotlinFilename
,
mainCallParameters
,
ecmaVersions
);
runRhinoTests
(
getOutputFilePaths
(
kotlinFilename
,
ecmaVersions
),
new
RhinoFunctionNativeObjectResultChecker
(
"test.browser"
,
"foo"
,
"Some Dynamically Created Content!!!"
));
}
@Override
protected
Map
<
String
,
Object
>
getRhinoTestVariables
()
throws
Exception
{
Document
document
=
DocumentBuilderFactory
.
newInstance
().
newDocumentBuilder
().
newDocument
();
Element
root
=
document
.
createElement
(
"root"
);
//root.setIdAttribute("foo", true);
root
.
setAttribute
(
"id"
,
"foo"
);
root
.
setIdAttribute
(
"id"
,
true
);
document
.
appendChild
(
root
);
// lets test it actually works
Element
foo
=
document
.
getElementById
(
"foo"
);
assertNotNull
(
foo
);
Map
<
String
,
Object
>
answer
=
new
HashMap
<
String
,
Object
>();
answer
.
put
(
"document"
,
document
);
return
answer
;
}
}
js/js.translator/testFiles/stdlib/cases/browserDocumentAccess.kt
浏览文件 @
adf38a06
...
...
@@ -2,9 +2,10 @@ package test.browser
import
kotlin.browser.document
fun
foo
()
{
fun
foo
()
:
String
{
val
element
=
document
.
getElementById
(
"foo"
)
if
(
element
!=
null
)
{
element
.
appendChild
(
document
.
createTextNode
(
"Some Dynamically Created Conten
e
t!!!"
))
element
.
appendChild
(
document
.
createTextNode
(
"Some Dynamically Created Content!!!"
))
}
return
element
.
getTextContent
()
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录