Format Long properties
Bug: 261331482 Test: npm run test:unit Change-Id: If760435ad364205f1a1cc6823630ff3f45bd6707
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import Long from "long";
|
||||
import { PropertiesTreeGenerator } from "viewers/common/properties_tree_generator";
|
||||
import {PropertiesTreeNode} from "./ui_tree_utils";
|
||||
|
||||
@@ -41,6 +42,18 @@ describe("PropertiesTreeGenerator", () => {
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it("handles longs", () => {
|
||||
const input = new Long(10, 100, false);
|
||||
const actual = new PropertiesTreeGenerator().generate("root", input);
|
||||
|
||||
const expected: PropertiesTreeNode = {
|
||||
propertyKey: "root",
|
||||
propertyValue: "429496729610"
|
||||
};
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it("handles string", () => {
|
||||
const input = "value";
|
||||
const actual = new PropertiesTreeGenerator().generate("root", input);
|
||||
|
||||
@@ -57,6 +57,9 @@ class PropertiesTreeGenerator {
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
if (this.isLong(value)) {
|
||||
return value.toString();
|
||||
}
|
||||
if (Array.isArray(value) && value.length === 0) {
|
||||
return "[]";
|
||||
}
|
||||
@@ -65,6 +68,12 @@ class PropertiesTreeGenerator {
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private isLong(value: any) {
|
||||
return Object.prototype.hasOwnProperty.call(value, "high") &&
|
||||
Object.prototype.hasOwnProperty.call(value, "low") &&
|
||||
Object.prototype.hasOwnProperty.call(value, "unsigned");
|
||||
}
|
||||
}
|
||||
|
||||
export {PropertiesTreeGenerator};
|
||||
|
||||
Reference in New Issue
Block a user