<commit_before>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package khttp.structures.maps

import khttp.MavenSpek
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class CaseInsensitiveMapSpec : MavenSpek() {
    override fun test() {
        given("a case-insensitive map initialized with a backing map") {
            val backingMap = mapOf("a" to "b", "c" to "d")
            val caseInsensitiveMap = CaseInsensitiveMap(backingMap)
            on("accessing a mapping") {
                val backed = backingMap["a"]
                val lower = caseInsensitiveMap["a"]
                val upper = caseInsensitiveMap["A"]
                it("should be the same value as in the backing map") {
                    assertEquals(backed, lower)
                }
                it("should be the same value as in the backing map") {
                    assertEquals(backed, upper)
                }
                it("should have an equal upper and lower value") {
                    assertTrue(upper == lower)
                }
            }
            on("checking if a mapping is present") {
                val backed = backingMap.containsKey("c")
                val lower = caseInsensitiveMap.containsKey("c")
                val upper = caseInsensitiveMap.containsKey("C")
                it("should be the same value as the result for the backing map") {
                    assertEquals(backed, lower)
                }
                it("should be the same value as the result for the backing map") {
                    assertEquals(backed, upper)
                }
                it("should have an equal upper and lower value") {
                    assertTrue(upper == lower)
                }
            }
            on("toString") {
                val backing = backingMap.toString()
                val insensitive = caseInsensitiveMap.toString()
                it("should be the same string returned by the backing map") {
                    assertEquals(backing, insensitive)
                }
            }
        }
    }
}<commit_msg>Updated: Add tests for branches in CaseInsensitiveMap<commit_after>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package khttp.structures.maps

import khttp.MavenSpek
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class CaseInsensitiveMapSpec : MavenSpek() {
    override fun test() {
        given("a case-insensitive map initialized with a backing map") {
            val backingMap = mapOf("a" to "b", "c" to "d")
            val caseInsensitiveMap = CaseInsensitiveMap(backingMap)
            on("accessing a mapping") {
                val backed = backingMap["a"]
                val lower = caseInsensitiveMap["a"]
                val upper = caseInsensitiveMap["A"]
                it("should be the same value as in the backing map") {
                    assertEquals(backed, lower)
                }
                it("should be the same value as in the backing map") {
                    assertEquals(backed, upper)
                }
                it("should have an equal upper and lower value") {
                    assertTrue(upper == lower)
                }
            }
            on("checking if a mapping is present") {
                val backed = backingMap.containsKey("c")
                val lower = caseInsensitiveMap.containsKey("c")
                val upper = caseInsensitiveMap.containsKey("C")
                it("should be the same value as the result for the backing map") {
                    assertEquals(backed, lower)
                }
                it("should be the same value as the result for the backing map") {
                    assertEquals(backed, upper)
                }
                it("should have an equal upper and lower value") {
                    assertTrue(upper == lower)
                }
            }
            on("toString") {
                val backing = backingMap.toString()
                val insensitive = caseInsensitiveMap.toString()
                it("should be the same string returned by the backing map") {
                    assertEquals(backing, insensitive)
                }
            }
            on("checking for invalid mappings") {
                it("should be null") {
                    assertFalse(caseInsensitiveMap.containsKeyRaw(null))
                }
                it("should be null") {
                    assertFalse(caseInsensitiveMap.containsKeyRaw(object {}))
                }
                it("should be null") {
                    assertEquals(Unit, caseInsensitiveMap.getRaw(null))
                    // KT-9963
                    // assertNull(caseInsensitiveMap.getRaw(null))
                }
                it("should be null") {
                    assertEquals(Unit, caseInsensitiveMap.getRaw(object {}))
                    // KT-9963
                    // assertNull(caseInsensitiveMap.getRaw(object {}))
                }
                it("should be false") {
                    assertFalse(caseInsensitiveMap.containsKey("b"))
                }
                it("should be false") {
                    assertFalse(caseInsensitiveMap.containsKey("B"))
                }
            }
        }
        given("a case-insensitive map initialized with an empty backing map") {
            val backingMap = mapOf<String, String>()
            val caseInsensitiveMap = CaseInsensitiveMap(backingMap)
            on("checking for invalid mappings") {
                it("should be null") {
                    assertFalse(caseInsensitiveMap.containsKeyRaw(null))
                }
                it("should be null") {
                    assertFalse(caseInsensitiveMap.containsKeyRaw(object {}))
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08547704330836861, 'fraction_numerical': 0.0026050146532074245, 'mean_word_length': 1.5032599837000815, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7320362', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1412, 'n_words': 442}