Skip to content

Commit

Permalink
Add test for json included in description of #1206 (#1270)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccleva authored Jan 3, 2025
1 parent c5afc31 commit a923338
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions json/src/test/java/tech/tablesaw/io/json/JsonReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@

import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Test;
import tech.tablesaw.api.ColumnType;
import tech.tablesaw.api.IntColumn;
import tech.tablesaw.api.Table;
import tech.tablesaw.io.Source;

public class JsonReaderTest {

Expand Down Expand Up @@ -110,4 +114,18 @@ public void testCustomizedColumnTypeAllCustomized() throws IOException {

assertArrayEquals(columnTypes, new ColumnType[] {STRING, STRING});
}

@Test
void testColumnOrderIsPreserved() {
String json =
"[{\"日期\":\"1991-04-03\",\"开盘\":49,\"收盘\":49,\"最高\":49,\"最低\":49,\"成交量\":1,\"成交额\":5000,\"振幅\":0,\"涨跌幅\":22.5,\"涨跌额\":9,\"换手率\":0},"
+ "{\"日期\":\"1991-04-04\",\"开盘\":48.76,\"收盘\":48.76,\"最高\":48.76,\"最低\":48.76,\"成交量\":3,\"成交额\":15000,\"振幅\":0,\"涨跌幅\":-0.49,\"涨跌额\":-0.24,\"换手率\":0}]\n";

List<String> header = Arrays.asList("日期", "开盘", "收盘", "最高", "最低", "成交量", "成交额", "振幅", "涨跌幅", "涨跌额", "换手率");

Table table = new JsonReader().read(Source.fromString(json));

assertEquals(header, table.columnNames());
}

}

0 comments on commit a923338

Please sign in to comment.