# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

-- Test `.emb` for the `bits` construct.

[$default byte_order: "LittleEndian"]
[(cpp) namespace: "emboss::test"]


bits OneByte:
  7 [+1]  Flag  high_bit
  6 [+1]  Flag  less_high_bit
  2 [+4]  UInt  mid_nibble
  1 [+1]  Flag  less_low_bit
  0 [+1]  Flag  low_bit


bits FourByte:
  bits TwoByteWithGaps:
    15 [+1]  Flag  high_bit
    6  [+4]  UInt  mid_nibble
    0  [+1]  Flag  low_bit

  28 [+4]   UInt             high_nibble
  20 [+8]   OneByte          one_byte
  4  [+16]  TwoByteWithGaps  two_byte
  0  [+4]   UInt             raw_low_nibble
    # Check that the [requires] attribute works on bits fields just like it does
    # on struct fields.
    [requires: 1 <= this <= 15]
  let low_nibble = raw_low_nibble + 100


bits ArrayInBits:
  15 [+1]   Flag    lone_flag
  0  [+12]  Flag[]  flags


struct ArrayInBitsInStruct:
  0 [+2]  ArrayInBits  array_in_bits


struct StructOfBits:
  0                   [+1]  OneByte                   one_byte
  1                   [+2]  FourByte.TwoByteWithGaps  two_byte
  3                   [+4]  FourByte                  four_byte
  one_byte.mid_nibble [+1]  UInt                      located_byte


struct BitArray:
  0 [+8]  OneByte[8]  one_byte
