< Summary

Class:GDX.DataTables.DataBinding.Formats.JavaScriptObjectNotationFormat
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/DataTables/DataBinding/Formats/JavaScriptObjectNotationFormat.cs
Covered lines:10
Uncovered lines:31
Coverable lines:41
Total lines:94
Line coverage:24.3% (10 of 41)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:11
Method coverage:27.2% (3 of 11)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
JavaScriptObjectNotationFormat()0%110100%
Finalize()0%2100%
GetBindingTimestamp(...)0%2100%
GetFilePreferredExtension()0%2100%
GetFriendlyName()0%110100%
IsFileHeader(...)0%2100%
GetImportDialogExtensions()0%2100%
IsOnDiskFormat()0%110100%
IsUri(...)0%2100%
Pull(...)0%12300%
Push(...)0%6200%

File(s)

./Packages/com.dotbunny.gdx/GDX/DataTables/DataBinding/Formats/JavaScriptObjectNotationFormat.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.IO;
 7using System.Text;
 8using UnityEngine;
 9
 10namespace GDX.DataTables.DataBinding.Formats
 11{
 12    /// <summary>
 13    ///     A JavaScript Object Notation format.
 14    /// </summary>
 15    class JavaScriptObjectNotationFormat : FormatBase
 16    {
 117        public JavaScriptObjectNotationFormat()
 118        {
 19            // We can register the format this way because we automatically include these formats in the
 20            // DataBindingsProvider as private members.
 121            DataBindingProvider.RegisterFormat(this);
 122        }
 23
 24        ~JavaScriptObjectNotationFormat()
 025        {
 026            DataBindingProvider.UnregisterFormat(this);
 027        }
 28
 29        /// <inheritdoc />
 30        public override DateTime GetBindingTimestamp(string uri)
 031        {
 032            return File.GetLastWriteTimeUtc(uri);
 033        }
 34
 35        /// <inheritdoc />
 36        public override string GetFilePreferredExtension()
 037        {
 038            return "json";
 039        }
 40
 41        /// <inheritdoc />
 42        public override string GetFriendlyName()
 443        {
 444            return "JSON";
 445        }
 46
 47        /// <inheritdoc />
 48        public override bool IsFileHeader(string header)
 049        {
 050            return header.StartsWith("{\"DataVersion\":", StringComparison.OrdinalIgnoreCase);
 051        }
 52
 53        /// <inheritdoc />
 54        public override string[] GetImportDialogExtensions()
 055        {
 056            return new[] { GetFriendlyName(), GetFilePreferredExtension() };
 057        }
 58
 59        /// <inheritdoc />
 60        public override bool IsOnDiskFormat()
 461        {
 462            return true;
 463        }
 64
 65        /// <inheritdoc />
 66        public override bool IsUri(string uri)
 067        {
 068            return uri.EndsWith(GetFilePreferredExtension(), StringComparison.OrdinalIgnoreCase);
 069        }
 70
 71        /// <inheritdoc />
 72        public override SerializableTable Pull(string uri, ulong currentDataVersion, int currentStructuralVersion)
 073        {
 074            if (uri == null || !File.Exists(uri))
 075            {
 076                return null;
 77            }
 78
 079            return JsonUtility.FromJson<SerializableTable>(File.ReadAllText(uri));
 080        }
 81
 82        /// <inheritdoc />
 83        public override bool Push(string uri, SerializableTable serializableTable)
 084        {
 085            if (uri == null)
 086            {
 087                return false;
 88            }
 89
 090            File.WriteAllText(uri, JsonUtility.ToJson(serializableTable), new UTF8Encoding());
 091            return File.Exists(uri);
 092        }
 93    }
 94}

Coverage by test methods





Methods/Properties

JavaScriptObjectNotationFormat()
Finalize()
GetBindingTimestamp(System.String)
GetFilePreferredExtension()
GetFriendlyName()
IsFileHeader(System.String)
GetImportDialogExtensions()
IsOnDiskFormat()
IsUri(System.String)
Pull(System.String, System.UInt64, System.Int32)
Push(System.String, GDX.DataTables.DataBinding.SerializableTable)