#####################################################################################
#
#  Copyright (c) Microsoft Corporation. All rights reserved.
#
#  This source code is subject to terms and conditions of the Shared Source License
#  for IronPython. A copy of the license can be found in the License.html file
#  at the root of this distribution. If you can not locate the Shared Source License
#  for IronPython, please send an email to ironpy@microsoft.com.
#  By using this source code in any fashion, you are agreeing to be bound by
#  the terms of the Shared Source License for IronPython.
#
#  You must not remove this notice, or any other, from this software.
#
######################################################################################

from Util.Debug import *
items = 0

d = {'key1': 'value1', 'key2': 'value2'}
for key, value in d.iteritems():
     global items
     items += 1
     Assert((key, value) == ('key1', 'value1') or (key,value) == ('key2', 'value2'))

Assert(items == 2)

Assert(d["key1"] == "value1")
Assert(d["key2"] == "value2")

def getitem(d,k):
    d[k]

AssertError(KeyError, getitem, d, "key3")

x = d.get("key3")
Assert(x == None)
Assert(d["key1"] == d.get("key1"))
Assert(d["key2"] == d.get("key2"))
Assert(d.get("key3", "value3") == "value3")

AssertError(KeyError, getitem, d, "key3")
Assert(d.setdefault("key3") == None)
Assert(d.setdefault("key4", "value4") == "value4")
Assert(d["key3"] == None)
Assert(d["key4"] == "value4")


d2= dict(key1 = 'value1', key2 = 'value2')
Assert(d2['key1'] == 'value1')


## inherit from a dictionary
class MyDict(dict):
    def __setitem__(self, *args):
            super(MyDict, self).__setitem__(*args)

a = MyDict()
a[0] = 'abc'


class MyDict(dict):
    def __setitem__(self, *args):
        dict.__setitem__(self, *args)

a = MyDict()
a[0] = 'abc'

#########################################
# verify function environments, FieldIdDict,
# custom old class dict, and module environments
# all local identical to normal dictionaries

x = {}

class C: pass

AreEqual(dir(x), dir(C.__dict__))

class C: 
    xx = 'abc'
    yy = 'def'
    pass

AreEqual(dir(x), dir(C.__dict__))

class C: 
    x0 = 'abc'
    x1 = 'def'
    x2 = 'aaa'
    x3 = 'aaa'
    pass

AreEqual(dir(x), dir(C.__dict__))

class C: 
    x0 = 'abc'
    x1 = 'def'
    x2 = 'aaa'
    x3 = 'aaa'
    x4 = 'abc'
    x5 = 'def'
    x6 = 'aaa'
    x7 = 'aaa'
    x0 = 'abc'
    pass

AreEqual(dir(x), dir(C.__dict__))

class C: 
    x0 = 'abc'
    x1 = 'def'
    x2 = 'aaa'
    x3 = 'aaa'
    x4 = 'abc'
    x5 = 'def'
    x6 = 'aaa'
    x7 = 'aaa'
    x0 = 'abc'
    x10 = 'abc'
    x11 = 'def'
    x12 = 'aaa'
    x13 = 'aaa'
    x14 = 'abc'
    x15 = 'def'
    x16 = 'aaa'
    x17 = 'aaa'
    x10 = 'abc'
    pass

AreEqual(dir(x), dir(C.__dict__))


class C: 
    x0 = 'abc'
    x1 = 'def'
    x2 = 'aaa'
    x3 = 'aaa'
    x4 = 'abc'
    x5 = 'def'
    x6 = 'aaa'
    x7 = 'aaa'
    x0 = 'abc'
    x10 = 'abc'
    x11 = 'def'
    x12 = 'aaa'
    x13 = 'aaa'
    x14 = 'abc'
    x15 = 'def'
    x16 = 'aaa'
    x17 = 'aaa'
    x10 = 'abc'
    x20 = 'abc'
    x21 = 'def'
    x22 = 'aaa'
    x23 = 'aaa'
    x24 = 'abc'
    x25 = 'def'
    x26 = 'aaa'
    x27 = 'aaa'
    x20 = 'abc'
    x110 = 'abc'
    x111 = 'def'
    x112 = 'aaa'
    x113 = 'aaa'
    x114 = 'abc'
    x115 = 'def'
    x116 = 'aaa'
    x117 = 'aaa'
    x110 = 'abc'
    pass

AreEqual(dir(x), dir(C.__dict__))


a = C()
AreEqual(dir(x), dir(a.__dict__))

a = C()
a.abc = 'def'
a.ghi = 'def'
AreEqual(dir(x), dir(a.__dict__))

if is_cli:
    # cpython does not have __dict__ at the module level?
    AreEqual(dir(x), dir(__dict__))
