|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2017, 2020, Oracle and/or its affiliates. |
3 | 3 | * Copyright (c) 2013, Regents of the University of California
|
4 | 4 | *
|
5 | 5 | * All rights reserved.
|
@@ -54,36 +54,78 @@ public void del() {
|
54 | 54 | assertPrints("{3: 4}\n", source);
|
55 | 55 | }
|
56 | 56 |
|
| 57 | + @Test |
| 58 | + public void dict() { |
| 59 | + String source = "print(type({}))\n" + |
| 60 | + "print(type(iter({1: 'a', 2: 'b'})))\n" + |
| 61 | + "print({})\n" + |
| 62 | + "print({1: 'a'})\n" + |
| 63 | + "print({1: 'a', 2: 'b'})\n"; |
| 64 | + |
| 65 | + assertPrints("<class 'dict'>\n" + |
| 66 | + "<class 'dict_keyiterator'>\n" + |
| 67 | + "{}\n" + |
| 68 | + "{1: 'a'}\n" + |
| 69 | + "{1: 'a', 2: 'b'}\n", source); |
| 70 | + |
| 71 | + source = "d = {1: 1}\n" + |
| 72 | + "d.__setitem__(2, d)\n" + |
| 73 | + "print(d)\n"; |
| 74 | + assertPrints("{1: 1, 2: {...}}\n", source); |
| 75 | + } |
| 76 | + |
57 | 77 | @Test
|
58 | 78 | public void dictViewKeys() {
|
59 | 79 | String source = "print(type({}.keys()))\n" +
|
60 | 80 | "print(type(iter({1: 'a', 2: 'b'}.keys())))\n" +
|
| 81 | + "print({}.keys())\n" + |
| 82 | + "print({1: 'a'}.keys())\n" + |
61 | 83 | "print({1: 'a', 2: 'b'}.keys())\n";
|
62 | 84 |
|
63 | 85 | assertPrints("<class 'dict_keys'>\n" +
|
64 |
| - "<class 'dict_keysiterator'>\n" + |
| 86 | + "<class 'dict_keyiterator'>\n" + |
| 87 | + "dict_keys([])\n" + |
| 88 | + "dict_keys([1])\n" + |
65 | 89 | "dict_keys([1, 2])\n", source);
|
66 | 90 | }
|
67 | 91 |
|
68 | 92 | @Test
|
69 | 93 | public void dictViewValues() {
|
70 | 94 | String source = "print(type({}.values()))\n" +
|
71 | 95 | "print(type(iter({1: 'a', 2: 'b'}.values())))\n" +
|
| 96 | + "print({}.values())\n" + |
| 97 | + "print({1: 'a'}.values())\n" + |
72 | 98 | "print({1: 'a', 2: 'b'}.values())\n";
|
73 | 99 |
|
74 | 100 | assertPrints("<class 'dict_values'>\n" +
|
75 |
| - "<class 'dict_valuesiterator'>\n" + |
| 101 | + "<class 'dict_valueiterator'>\n" + |
| 102 | + "dict_values([])\n" + |
| 103 | + "dict_values(['a'])\n" + |
76 | 104 | "dict_values(['a', 'b'])\n", source);
|
| 105 | + |
| 106 | + source = "d = {1: 1}\n" + |
| 107 | + "d.__setitem__(2, d)\n" + |
| 108 | + "print(d.values())\n"; |
| 109 | + assertPrints("dict_values([1, {1: 1, 2: {...}}])\n", source); |
77 | 110 | }
|
78 | 111 |
|
79 | 112 | @Test
|
80 | 113 | public void dictViewItems() {
|
81 | 114 | String source = "print(type({}.items()))\n" +
|
82 | 115 | "print(type(iter({1: 'a', 2: 'b'}.items())))\n" +
|
| 116 | + "print({}.items())\n" + |
| 117 | + "print({1: 'a'}.items())\n" + |
83 | 118 | "print({1: 'a', 2: 'b'}.items())\n";
|
84 | 119 |
|
85 | 120 | assertPrints("<class 'dict_items'>\n" +
|
86 |
| - "<class 'dict_itemsiterator'>\n" + |
| 121 | + "<class 'dict_itemiterator'>\n" + |
| 122 | + "dict_items([])\n" + |
| 123 | + "dict_items([(1, 'a')])\n" + |
87 | 124 | "dict_items([(1, 'a'), (2, 'b')])\n", source);
|
| 125 | + |
| 126 | + source = "d = {1: 1}\n" + |
| 127 | + "d.__setitem__(2, d)\n" + |
| 128 | + "print(d.items())\n"; |
| 129 | + assertPrints("dict_items([(1, 1), (2, {1: 1, 2: {...}})])\n", source); |
88 | 130 | }
|
89 | 131 | }
|
0 commit comments