File size: 1,195 Bytes
6851d40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// RUN: %verify "%s"

/*******************************************************************************
 *  Copyright by the contributors to the Dafny Project
 *  SPDX-License-Identifier: MIT
 *******************************************************************************/

include "../../src/Unicode/Utf16EncodingForm.dfy"

module Utf16EncodingFormExamples {
  import Unicode
  import opened Utf16EncodingForm

  const TEST_SCALAR_VALUES: seq<(Unicode.ScalarValue, WellFormedCodeUnitSeq)> := [
    // One code unit: dollar sign
    (0x0024, [0x0024]),
    // Two code units: money bag emoji
    (0x1F4B0, [0xD83D, 0xDCB0])
  ]

  lemma TestEncodeScalarValue()
    ensures forall pair | pair in TEST_SCALAR_VALUES
              :: EncodeScalarValue(pair.0) == pair.1
  {}

  // Because surrogate code points are not Unicode scalar values, isolated UTF-16 code units in the range
  // D800_16 .. DFFF_16 are ill-formed. (Section 3.9 D91)
  const TEST_ILL_FORMED_SEQUENCES: seq<CodeUnitSeq> := [
    [0xD800],
    [0xDABC],
    [0xDFFF]
  ]

  lemma TestDecodeIllFormedSequence()
    ensures forall s | s in TEST_ILL_FORMED_SEQUENCES
              :: DecodeCodeUnitSequenceChecked(s).None?
  {}
}