RegressionTests__MutabilityTest.st
author Stefan Vogel <sv@exept.de>
Tue, 11 Jun 2019 10:34:41 +0200
changeset 2321 32ea6329f5ad
parent 2313 aada90d91658
child 2324 98d710589596
permissions -rw-r--r--
class: stx_goodies_regression class changed: #classNamesAndAttributes make classes autoloaded that stc cannot compile (yet)

"{ Encoding: utf8 }"

"{ 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"

    |arr arr2|

    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).  "/ 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"
!

test02_mutability
    "literals are mutable - if specified so"
    

    |arr|

   "/ 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"
! !

!MutabilityTest class methodsFor:'documentation'!

version_CVS
    ^ '$Header$'
! !