< Summary

Class:NanoCLang.Entities.BlockOffset
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\BlockOffset.cs
Covered lines:14
Uncovered lines:3
Coverable lines:17
Total lines:45
Line coverage:82.3% (14 of 17)
Covered branches:3
Total branches:4
Branch coverage:75% (3 of 4)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Offset()100%1100%
Tokens()100%1100%
Replace(...)100%2100%
Clone()100%1100%
Equals(...)100%1100%
Equals(...)50%2100%
GetHashCode()100%10%
op_Equality(...)100%10%
op_Inequality(...)100%10%

File(s)

C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Expression\PureExpression\BlockOffset.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4namespace NanoCLang.Entities {
 5    /// <summary>
 6    /// Provides a class for block offset constants.
 7    /// </summary>
 8    public class BlockOffset : VariableExpression, IEquatable<BlockOffset?>, ICloneable {
 9        /// <summary>
 10        /// Creates a new block <paramref name="offset"/>.
 11        /// </summary>
 12        /// <param name="offset">Offset of the block offset literal.</param>
 2813        public BlockOffset(int offset) : base(Heap.OffsetVar(offset)) {
 1414            Offset = offset;
 1415        }
 16        /// <summary>
 17        /// The offset in the heap that this entity refers to.
 18        /// </summary>
 7319        public int Offset { get; }
 20        /// <inheritdoc/>
 4721        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 4722            yield return "@";
 4723            yield return Offset.ToString();
 4724        }
 25        /// <inheritdoc/>
 26        public override PureExpression Replace(Substitutor sub)
 727            => sub.BlockOffsets.TryGetValue(Offset, out var exp)
 728            ? exp
 729            : (BlockOffset)Clone();
 30        /// <inheritdoc/>
 531        public override object Clone() => new BlockOffset(Offset);
 32        #region Equality checks
 33        /// <inheritdoc/>
 734        public override bool Equals(object? obj) => Equals(obj as BlockOffset);
 35        /// <inheritdoc/>
 736        public bool Equals(BlockOffset? other) => !(other is null) && Offset == other.Offset;
 37        /// <inheritdoc/>
 038        public override int GetHashCode() => HashCode.Combine(Offset);
 39        /// <inheritdoc/>
 040        public static bool operator ==(BlockOffset? left, BlockOffset? right) => EqualityComparer<BlockOffset?>.Default.
 41        /// <inheritdoc/>
 042        public static bool operator !=(BlockOffset? left, BlockOffset? right) => !(left == right);
 43        #endregion
 44    }
 45}