Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Add more tests#7

Merged
PythonCoderAS merged 1 commit intomasterfrommore_test
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletionsarrayStringMap.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,11 @@ describe("Empty map", () => {
it ("Empty map entries returns empty array", () => {
assert([...arrayStringMap.entries()].length === 0);
})
it ("Empty map forEach", () => {
arrayStringMap.forEach(() => {
assert(false, "forEach should not be called");
});
})
})

describe("Map with one object", () => {
Expand DownExpand Up@@ -97,6 +102,16 @@ describe("Map with one object", () => {
// works as expected
assert(copiedMap._converterInfo.size === 0, "Converter map size is 0");
})
it ("Map forEach is called once", () => {
let count = 0;
arrayStringMap.forEach((value, key, map) => {
count++;
assert(value === sampleValue1, "Value is sampleValue1");
assert(key === sampleArray1, "Key is sampleArray1");
assert(map === arrayStringMap, "Map is arrayStringMap");
});
assert(count === 1, "ForEach is called once");
})
})

describe("Map with one object and different separator", () => {
Expand DownExpand Up@@ -138,6 +153,16 @@ describe("Map with one object and alternate array", () => {
assert([...arrayStringMap.values()].length === 1, "Array length is 1");
assert([...arrayStringMap.values()][0] === sampleValue2, "Value is sampleValue2");
})
it ("Map forEach is called once", () => {
let count = 0;
arrayStringMap.forEach((value, key, map) => {
count++;
assert(value === sampleValue2, "Value is sampleValue2");
assert(key === sampleArray2, "Key is sampleArray2");
assert(map === arrayStringMap, "Map is arrayStringMap");
});
assert(count === 1, "ForEach is called once");
})
})

describe("Map with two objects", () => {
Expand DownExpand Up@@ -222,4 +247,20 @@ describe("Map with two objects", () => {
// works as expected
assert(copiedMap._converterInfo.size === 1, "Converter map size is 1");
})
it("Map forEach is called twice", () => {
let count = 0;
arrayStringMap.forEach((value, key, map) => {
count++;
assert(map === arrayStringMap, "Map is arrayStringMap");
if (count === 0){
assert(key === sampleArray1, "Key is sampleArray1");
assert(value === sampleValue1, "Value is sampleValue1");
}
else if (count === 1){
assert(key === sampleArray3, "Key is sampleArray3");
assert(value === sampleValue2, "Value is sampleValue2");
}
});
assert(count === 2, "ForEach is called twice");
})
})
2 changes: 1 addition & 1 deletionarrayStringMap.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,7 +50,7 @@ export default class ArrayStringMap<K extends any[], V> implements Map<K, V> {
}
}

forEach(callbackfn: (value: V, key: K, map:Map<K, V>) => void, thisArg?: any): void {
forEach(callbackfn: (value: V, key: K, map:ArrayStringMap<K, V>) => void, thisArg?: any): void {
this._converterInfo.forEach((value, key) => {
// TypeScript complains that this will be undefined, but the items in
// `this._converterInfo` and `this._map` will always be defined in each other.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp