Implement JavaOnlyArray#getType
Reviewed By: AaaChiuuu Differential Revision: D3504601 fbshipit-source-id: 37dbbcdd8cc0523cb8f1673047995c4410e8f7be
This commit is contained in:
parent
ff31128200
commit
2b88482701
|
@ -90,6 +90,23 @@ public class JavaOnlyArray implements ReadableArray, WritableArray {
|
|||
|
||||
@Override
|
||||
public ReadableType getType(int index) {
|
||||
Object object = mBackingList.get(index);
|
||||
|
||||
if (object == null) {
|
||||
return ReadableType.Null;
|
||||
} else if (object instanceof Boolean) {
|
||||
return ReadableType.Boolean;
|
||||
} else if (object instanceof Double ||
|
||||
object instanceof Float ||
|
||||
object instanceof Integer) {
|
||||
return ReadableType.Number;
|
||||
} else if (object instanceof String) {
|
||||
return ReadableType.String;
|
||||
} else if (object instanceof ReadableArray) {
|
||||
return ReadableType.Array;
|
||||
} else if (object instanceof ReadableMap) {
|
||||
return ReadableType.Map;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JavaOnlyArray}
|
||||
*/
|
||||
public class JavaOnlyArrayTest {
|
||||
|
||||
@Test
|
||||
public void testGetType() throws Exception {
|
||||
JavaOnlyArray values = JavaOnlyArray.of(
|
||||
1,
|
||||
2f,
|
||||
3.,
|
||||
"4",
|
||||
false,
|
||||
JavaOnlyArray.of(),
|
||||
JavaOnlyMap.of(),
|
||||
null);
|
||||
ReadableType[] expectedTypes = new ReadableType[] {
|
||||
ReadableType.Number,
|
||||
ReadableType.Number,
|
||||
ReadableType.Number,
|
||||
ReadableType.String,
|
||||
ReadableType.Boolean,
|
||||
ReadableType.Array,
|
||||
ReadableType.Map,
|
||||
ReadableType.Null
|
||||
};
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
assertThat(values.getType(i)).isEqualTo(expectedTypes[i]);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue