RegressionTests__MutabilityTest.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 18:53:03 +0200
changeset 2327 bf482d49aeaf
parent 2324 98d710589596
permissions -rw-r--r--
#QUALITY by exept class: RegressionTests::StringTests added: #test82c_expanding

"{ Package: 'stx:goodies/regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#MutabilityTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'tests-Regression-Numbers'
!

!MutabilityTest class methodsFor:'documentation'!

documentation
"
    documentation to be added.

    class:
        <a short class summary here, describing what instances represent>

    responsibilities:    
        <describing what my main role is>

    collaborators:    
        <describing with whom and how I talk to>

    API:
        <public api and main messages>
        
    example:
        <a one-line examples on how to use - can also be in a separate example method>

    implementation:
        <implementation points>

    [author:]
        Claus Gittinger

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!MutabilityTest methodsFor:'tests'!

test01_immutability
    "literals are immutable - if specified so"
    
    <pragma: +STXExtendedArrayLiterals>
    <pragma: +arraysAreImmutable>

    |arr arr2|

    arr := #[1 2 3 4].
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed s8
    arr := #s8(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed s16
    arr := #s16(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed s32
    arr := #s32(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed s64
    arr := #s64(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed u1
    arr := #u1(0 1 1 0).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:1] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:1] raise:Error.
    self should:[arr2 at:1 put:2] raise:Error.

    "/ unboxed u8
    arr := #u8(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed u16
    arr := #u16(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed u32
    arr := #u32(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed u64
    arr := #s64(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed f16
    arr := #f16(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed f32
    arr := #f32(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.

    "/ unboxed f64
    arr := #f64(1 2 3 4).
    self assert:(arr isImmutable).  "/ because it comes from a literal
    self should:[arr at:1 put:10] raise:NoModificationError.

    arr2 := arr copy.
    self assert:(arr2 isImmutable not). 
    self shouldnt:[arr2 at:1 put:10] raise:Error.
    
    "
     self run:#test01_mutability
     self new test01_mutability
    "

    "Created: / 09-06-2019 / 15:49:37 / Claus Gittinger"
    "Modified: / 10-06-2019 / 20:50:21 / Claus Gittinger"
    "Modified: / 17-06-2019 / 15:11:09 / Stefan Reise"
!

test02_mutability
    "literals are mutable - if specified so"
    
    <pragma: +STXExtendedArrayLiterals>
    <pragma: -arraysAreImmutable>

    |arr|

    self skipIf:(self class compiledMethodAt:#test01_immutability)
                byteCode isNil
         description:'skipped because stc-compiled literals are always immutable'.

    arr := #[1 2 3 4].
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed s8
    arr := #s8(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed s16
    arr := #s16(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed s32
    arr := #s32(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed s64
    arr := #s64(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed u1
    arr := #u1(0 1 1 0).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:1] raise:NoModificationError.
    self should:[arr at:1 put:2] raise:Error.

    "/ unboxed u8
    arr := #u8(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed u16
    arr := #u16(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed u32
    arr := #u32(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed u64
    arr := #s64(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed f16
    arr := #f16(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed f32
    arr := #f32(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.

    "/ unboxed f64
    arr := #f64(1 2 3 4).
    self assert:(arr isImmutable not).  "/ because I specifid so
    self shouldnt:[arr at:1 put:10] raise:NoModificationError.
    
    "
     self run:#test01_mutability
     self new test01_mutability
    "

    "Created: / 09-06-2019 / 15:49:46 / Claus Gittinger"
    "Modified: / 17-06-2019 / 15:11:06 / Stefan Reise"
! !

!MutabilityTest class methodsFor:'documentation'!

version_CVS
    ^ '$Header$'
! !