1*99e0aae7SDavid Rees# Copyright 2019 Google LLC 2*99e0aae7SDavid Rees# 3*99e0aae7SDavid Rees# Licensed under the Apache License, Version 2.0 (the "License"); 4*99e0aae7SDavid Rees# you may not use this file except in compliance with the License. 5*99e0aae7SDavid Rees# You may obtain a copy of the License at 6*99e0aae7SDavid Rees# 7*99e0aae7SDavid Rees# https://www.apache.org/licenses/LICENSE-2.0 8*99e0aae7SDavid Rees# 9*99e0aae7SDavid Rees# Unless required by applicable law or agreed to in writing, software 10*99e0aae7SDavid Rees# distributed under the License is distributed on an "AS IS" BASIS, 11*99e0aae7SDavid Rees# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*99e0aae7SDavid Rees# See the License for the specific language governing permissions and 13*99e0aae7SDavid Rees# limitations under the License. 14*99e0aae7SDavid Rees 15*99e0aae7SDavid Rees-- Test `.emb` for the `bits` construct. 16*99e0aae7SDavid Rees 17*99e0aae7SDavid Rees[$default byte_order: "LittleEndian"] 18*99e0aae7SDavid Rees[(cpp) namespace: "emboss::test"] 19*99e0aae7SDavid Rees 20*99e0aae7SDavid Rees 21*99e0aae7SDavid Reesbits OneByte: 22*99e0aae7SDavid Rees 7 [+1] Flag high_bit 23*99e0aae7SDavid Rees 6 [+1] Flag less_high_bit 24*99e0aae7SDavid Rees 2 [+4] UInt mid_nibble 25*99e0aae7SDavid Rees 1 [+1] Flag less_low_bit 26*99e0aae7SDavid Rees 0 [+1] Flag low_bit 27*99e0aae7SDavid Rees 28*99e0aae7SDavid Rees 29*99e0aae7SDavid Reesbits FourByte: 30*99e0aae7SDavid Rees bits TwoByteWithGaps: 31*99e0aae7SDavid Rees 15 [+1] Flag high_bit 32*99e0aae7SDavid Rees 6 [+4] UInt mid_nibble 33*99e0aae7SDavid Rees 0 [+1] Flag low_bit 34*99e0aae7SDavid Rees 35*99e0aae7SDavid Rees 28 [+4] UInt high_nibble 36*99e0aae7SDavid Rees 20 [+8] OneByte one_byte 37*99e0aae7SDavid Rees 4 [+16] TwoByteWithGaps two_byte 38*99e0aae7SDavid Rees 0 [+4] UInt raw_low_nibble 39*99e0aae7SDavid Rees # Check that the [requires] attribute works on bits fields just like it does 40*99e0aae7SDavid Rees # on struct fields. 41*99e0aae7SDavid Rees [requires: 1 <= this <= 15] 42*99e0aae7SDavid Rees let low_nibble = raw_low_nibble + 100 43*99e0aae7SDavid Rees 44*99e0aae7SDavid Rees 45*99e0aae7SDavid Reesbits ArrayInBits: 46*99e0aae7SDavid Rees 15 [+1] Flag lone_flag 47*99e0aae7SDavid Rees 0 [+12] Flag[] flags 48*99e0aae7SDavid Rees 49*99e0aae7SDavid Rees 50*99e0aae7SDavid Reesstruct ArrayInBitsInStruct: 51*99e0aae7SDavid Rees 0 [+2] ArrayInBits array_in_bits 52*99e0aae7SDavid Rees 53*99e0aae7SDavid Rees 54*99e0aae7SDavid Reesstruct StructOfBits: 55*99e0aae7SDavid Rees 0 [+1] OneByte one_byte 56*99e0aae7SDavid Rees 1 [+2] FourByte.TwoByteWithGaps two_byte 57*99e0aae7SDavid Rees 3 [+4] FourByte four_byte 58*99e0aae7SDavid Rees one_byte.mid_nibble [+1] UInt located_byte 59*99e0aae7SDavid Rees 60*99e0aae7SDavid Rees 61*99e0aae7SDavid Reesstruct BitArray: 62*99e0aae7SDavid Rees 0 [+8] OneByte[8] one_byte 63