Commit 12b6b23d authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

mojo-ts: Add tests for imported constants

Adds some simple tests to ensure imported constants and constants
specified in terms of other constants have the correct values.

The CL used to do more, but https://crrev.com/c/2204846 made it all
redundant.

Bug: 1002798,1008761
Change-Id: I2de4b945848c8b4ad358fbcd296189c8d989cbfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1839752Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772490}
parent af57d718
......@@ -11,6 +11,11 @@ mojom("test_interfaces") {
sources = [
"constants.test-mojom",
"enums.test-mojom",
"export1.test-mojom",
"export2.test-mojom",
"export3.test-mojom",
"export4.test-mojom",
"import.test-mojom",
"module.test-mojom",
]
use_typescript_sources = true
......
......@@ -42,3 +42,6 @@ const float kFloatNegativeInfinity = float.NEGATIVE_INFINITY;
const float kFloatNaN = float.NAN;
const string kStringValue = "test string contents";
const uint8 kNamedValue1 = kUint8Value;
const double kNamedValue2 = kDoubleInfinity;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo.tstest.exported;
const uint8 kOne = 1;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo.tstest.exported;
const uint8 kTwo = 2;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo.tstest.exported;
const uint8 kThree = 3;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo.tstest.exported;
import "mojo/public/js/ts/bindings/tests/export3.test-mojom";
const uint8 kAlsoThree = mojo.tstest.exported.kThree;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo.tstest.imported;
import "mojo/public/js/ts/bindings/tests/export1.test-mojom";
import "mojo/public/js/ts/bindings/tests/export2.test-mojom";
import "mojo/public/js/ts/bindings/tests/export4.test-mojom";
const uint8 kImportedOne = mojo.tstest.exported.kOne;
const uint8 kImportedTwo = mojo.tstest.exported.kTwo;
const uint8 kImportedThree = mojo.tstest.exported.kAlsoThree;
......@@ -57,8 +57,8 @@ class Generator(generator.Generator):
def GetFilters(self):
ts_filters = {
"typescript_type_with_nullability": self._TypescriptTypeWithNullability,
"constant_value": self._ConstantValue,
"typescript_type_with_nullability": self._TypescriptTypeWithNullability,
"constant_value": self._ConstantValue,
}
return ts_filters
......@@ -80,7 +80,6 @@ class Generator(generator.Generator):
self.Write(self._GenerateESModulesBindings(),
"%s-lite.m.ts" % self.module.path)
def _TypescriptType(self, kind):
if kind in mojom.PRIMITIVES:
return _kind_to_typescript_type[kind]
......
......@@ -81,6 +81,14 @@
constant: mojo.tstest.STRING_VALUE,
expectedValue: "test string contents",
type: 'string'
}, {
constant: mojo.tstest.NAMED_VALUE1,
expectedValue: mojo.tstest.UINT8_VALUE,
type: 'int8 that points to another constant'
}, {
constant: mojo.tstest.NAMED_VALUE2,
expectedValue: mojo.tstest.DOUBLE_INFINITY,
type: 'double that points to another constant'
}].forEach(testCase => {
test(
() => assert_equals(testCase.constant, testCase.expectedValue),
......
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings_lite.js"></script>
<script src="/gen/mojo/public/js/ts/bindings/tests/import.test-mojom-lite.js"></script>
<script>
'use strict';
test(() => {
assert_equals(mojo.tstest.imported.IMPORTED_ONE, 1);
assert_equals(mojo.tstest.imported.IMPORTED_TWO, 2);
assert_equals(mojo.tstest.imported.IMPORTED_THREE, 3);
}, 'Checks that values of imported constants is correct');
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment